Skip to content

Commit fcf2ce7

Browse files
authored
Merge pull request #1254 from ljharb/travis
Update deps, fix tests
2 parents 1cd82eb + 64d9be7 commit fcf2ce7

12 files changed

+219
-154
lines changed

.travis.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ matrix:
3232
node_js: 6
3333
- env: PACKAGE=resolvers/webpack
3434
node_js: 4
35+
3536
- os: osx
3637
env: ESLINT_VERSION=5
3738
node_js: 10
@@ -44,16 +45,23 @@ matrix:
4445
- os: osx
4546
env: ESLINT_VERSION=2
4647
node_js: 4
48+
4749
exclude:
4850
- node_js: '4'
4951
env: ESLINT_VERSION=5
52+
53+
fast_finish: true
54+
allow_failures:
55+
# issues with typescript deps in this version intersection
56+
- node_js: '4'
57+
env: ESLINT_VERSION=4
5058

5159
before_install:
5260
- 'nvm install-latest-npm'
5361
- 'if [ -n "${PACKAGE-}" ]; then cd "${PACKAGE}"; fi'
5462
install:
5563
- npm install
56-
- npm install --no-save eslint@$ESLINT_VERSION --ignore-scripts || true
64+
- 'if [ -n "${ESLINT_VERSION}" ]; then ./tests/dep-time-travel.sh; fi'
5765

5866
script:
5967
- 'npm test'

appveyor.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ environment:
33
matrix:
44
- nodejs_version: "10"
55
- nodejs_version: "8"
6-
- nodejs_version: "6"
7-
- nodejs_version: "4"
6+
# - nodejs_version: "6"
7+
# - nodejs_version: "4"
88

99
matrix:
1010
fast_finish: true
11-
allow_failures:
12-
- nodejs_version: "4" # for eslint 5
11+
12+
# allow_failures:
13+
# - nodejs_version: "4" # for eslint 5
1314

1415
# platform:
1516
# - x86

package.json

+18-18
Original file line numberDiff line numberDiff line change
@@ -44,45 +44,45 @@
4444
},
4545
"homepage": "https://github.com/benmosher/eslint-plugin-import",
4646
"devDependencies": {
47-
"babel-eslint": "8.0.x",
47+
"babel-eslint": "^8.2.6",
4848
"babel-plugin-istanbul": "^4.1.6",
4949
"babel-preset-es2015-argon": "latest",
5050
"babel-register": "^6.26.0",
51-
"babylon": "6.15.0",
51+
"babylon": "^6.15.0",
5252
"chai": "^3.5.0",
53-
"coveralls": "^3.0.0",
53+
"coveralls": "^3.0.2",
5454
"cross-env": "^4.0.0",
5555
"eslint": "2.x - 5.x",
5656
"eslint-import-resolver-node": "file:./resolvers/node",
57-
"eslint-import-resolver-typescript": "1.0.2",
57+
"eslint-import-resolver-typescript": "^1.0.2",
5858
"eslint-import-resolver-webpack": "file:./resolvers/webpack",
5959
"eslint-module-utils": "file:./utils",
6060
"eslint-plugin-import": "2.x",
61-
"gulp": "^3.9.0",
61+
"gulp": "^3.9.1",
6262
"gulp-babel": "6.1.2",
63-
"linklocal": "^2.6.0",
63+
"linklocal": "^2.8.2",
6464
"mocha": "^3.5.3",
65-
"nyc": "^11.7.1",
66-
"redux": "^3.0.4",
67-
"rimraf": "^2.6.2",
68-
"sinon": "^2.3.2",
69-
"typescript": "~2.8.1",
70-
"typescript-eslint-parser": "^15.0.0"
65+
"nyc": "^11.9.0",
66+
"redux": "^3.7.2",
67+
"rimraf": "^2.6.3",
68+
"sinon": "^2.4.1",
69+
"typescript": "^3.2.2",
70+
"typescript-eslint-parser": "^21.0.2"
7171
},
7272
"peerDependencies": {
7373
"eslint": "2.x - 5.x"
7474
},
7575
"dependencies": {
7676
"contains-path": "^0.1.0",
77-
"debug": "^2.6.8",
77+
"debug": "^2.6.9",
7878
"doctrine": "1.5.0",
79-
"eslint-import-resolver-node": "^0.3.1",
79+
"eslint-import-resolver-node": "^0.3.2",
8080
"eslint-module-utils": "^2.2.0",
81-
"has": "^1.0.1",
82-
"lodash": "^4.17.4",
83-
"minimatch": "^3.0.3",
81+
"has": "^1.0.3",
82+
"lodash": "^4.17.11",
83+
"minimatch": "^3.0.4",
8484
"read-pkg-up": "^2.0.0",
85-
"resolve": "^1.6.0"
85+
"resolve": "^1.9.0"
8686
},
8787
"nyc": {
8888
"require": [

src/ExportMap.js

+36-12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import doctrine from 'doctrine'
44

55
import debug from 'debug'
66

7+
import SourceCode from 'eslint/lib/util/source-code'
8+
79
import parse from 'eslint-module-utils/parse'
810
import resolve from 'eslint-module-utils/resolve'
911
import isIgnored, { hasValidExtension } from 'eslint-module-utils/ignore'
@@ -193,22 +195,28 @@ export default class ExportMap {
193195
* @param {...[type]} nodes [description]
194196
* @return {{doc: object}}
195197
*/
196-
function captureDoc(docStyleParsers) {
198+
function captureDoc(source, docStyleParsers) {
197199
const metadata = {}
198200
, nodes = Array.prototype.slice.call(arguments, 1)
199201

200202
// 'some' short-circuits on first 'true'
201203
nodes.some(n => {
202-
if (!n.leadingComments) return false
203-
204-
for (let name in docStyleParsers) {
205-
const doc = docStyleParsers[name](n.leadingComments)
206-
if (doc) {
207-
metadata.doc = doc
204+
try {
205+
// n.leadingComments is legacy `attachComments` behavior
206+
let leadingComments = n.leadingComments || source.getCommentsBefore(n)
207+
if (leadingComments.length === 0) return false
208+
209+
for (let name in docStyleParsers) {
210+
const doc = docStyleParsers[name](leadingComments)
211+
if (doc) {
212+
metadata.doc = doc
213+
}
208214
}
209-
}
210215

211-
return true
216+
return true
217+
} catch (err) {
218+
return false
219+
}
212220
})
213221

214222
return metadata
@@ -338,6 +346,8 @@ ExportMap.parse = function (path, content, context) {
338346
docStyleParsers[style] = availableDocStyleParsers[style]
339347
})
340348

349+
const source = makeSourceCode(content, ast)
350+
341351
// attempt to collect module doc
342352
if (ast.comments) {
343353
ast.comments.some(c => {
@@ -405,7 +415,7 @@ ExportMap.parse = function (path, content, context) {
405415
ast.body.forEach(function (n) {
406416

407417
if (n.type === 'ExportDefaultDeclaration') {
408-
const exportMeta = captureDoc(docStyleParsers, n)
418+
const exportMeta = captureDoc(source, docStyleParsers, n)
409419
if (n.declaration.type === 'Identifier') {
410420
addNamespace(exportMeta, n.declaration)
411421
}
@@ -441,12 +451,12 @@ ExportMap.parse = function (path, content, context) {
441451
case 'TSInterfaceDeclaration':
442452
case 'TSAbstractClassDeclaration':
443453
case 'TSModuleDeclaration':
444-
m.namespace.set(n.declaration.id.name, captureDoc(docStyleParsers, n))
454+
m.namespace.set(n.declaration.id.name, captureDoc(source, docStyleParsers, n))
445455
break
446456
case 'VariableDeclaration':
447457
n.declaration.declarations.forEach((d) =>
448458
recursivePatternCapture(d.id,
449-
id => m.namespace.set(id.name, captureDoc(docStyleParsers, d, n))))
459+
id => m.namespace.set(id.name, captureDoc(source, docStyleParsers, d, n))))
450460
break
451461
}
452462
}
@@ -531,3 +541,17 @@ function childContext(path, context) {
531541
path,
532542
}
533543
}
544+
545+
546+
/**
547+
* sometimes legacy support isn't _that_ hard... right?
548+
*/
549+
function makeSourceCode(text, ast) {
550+
if (SourceCode.length > 1) {
551+
// ESLint 3
552+
return new SourceCode(text, ast)
553+
} else {
554+
// ESLint 4, 5
555+
return new SourceCode({ text, ast })
556+
}
557+
}

src/rules/no-amd.js

+21-23
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,33 @@ import docsUrl from '../docsUrl'
1010
//------------------------------------------------------------------------------
1111

1212
module.exports = {
13-
meta: {
14-
type: 'suggestion',
15-
docs: {
16-
url: docsUrl('no-amd'),
17-
},
13+
meta: {
14+
type: 'suggestion',
15+
docs: {
16+
url: docsUrl('no-amd'),
1817
},
18+
},
1919

20-
create: function (context) {
20+
create: function (context) {
21+
return {
22+
'CallExpression': function (node) {
23+
if (context.getScope().type !== 'module') return
2124

22-
return {
25+
if (node.callee.type !== 'Identifier') return
26+
if (node.callee.name !== 'require' &&
27+
node.callee.name !== 'define') return
2328

24-
'CallExpression': function (node) {
25-
if (context.getScope().type !== 'module') return
29+
// todo: capture define((require, module, exports) => {}) form?
30+
if (node.arguments.length !== 2) return
2631

27-
if (node.callee.type !== 'Identifier') return
28-
if (node.callee.name !== 'require' &&
29-
node.callee.name !== 'define') return
32+
const modules = node.arguments[0]
33+
if (modules.type !== 'ArrayExpression') return
3034

31-
// todo: capture define((require, module, exports) => {}) form?
32-
if (node.arguments.length !== 2) return
35+
// todo: check second arg type? (identifier or callback)
3336

34-
const modules = node.arguments[0]
35-
if (modules.type !== 'ArrayExpression') return
37+
context.report(node, `Expected imports instead of AMD ${node.callee.name}().`)
38+
},
39+
}
3640

37-
// todo: check second arg type? (identifier or callback)
38-
39-
context.report(node, `Expected imports instead of AMD ${node.callee.name}().`)
40-
},
41-
}
42-
43-
},
41+
},
4442
}

tests/dep-time-travel.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# expected: ESLINT_VERSION numeric env var
4+
5+
npm install --no-save eslint@$ESLINT_VERSION --ignore-scripts || true
6+
7+
# use these alternate typescript dependencies for ESLint < v4
8+
if [[ "$ESLINT_VERSION" -lt "4" ]]; then
9+
echo "Downgrading babel-eslint..."
10+
npm i --no-save [email protected]
11+
12+
echo "Downgrading TypeScript dependencies..."
13+
npm i --no-save typescript-eslint-parser@15 [email protected]
14+
fi
15+
16+
# typescript-eslint-parser 1.1.1+ is not compatible with node 6
17+
if [[ "$TRAVIS_NODE_VERSION" -lt "8" ]]; then
18+
echo "Downgrading eslint-import-resolver-typescript..."
19+
npm i --no-save [email protected]
20+
fi

tests/files/deprecated.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ export const MY_TERRIBLE_ACTION = "ugh"
2727
* @deprecated this chain is awful
2828
* @type {String}
2929
*/
30-
export const CHAIN_A = "a"
30+
export const CHAIN_A = "a",
3131
/**
3232
* @deprecated so awful
3333
* @type {String}
3434
*/
35-
, CHAIN_B = "b"
35+
CHAIN_B = "b",
3636

3737
/**
3838
* @deprecated still terrible
3939
* @type {String}
4040
*/
41-
, CHAIN_C = "C"
41+
CHAIN_C = "C"
4242

4343
/**
4444
* this one is fine

tests/src/core/getExports.js

+1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ describe('ExportMap', function () {
318318
]
319319

320320
configs.forEach(([description, parserConfig]) => {
321+
321322
describe(description, function () {
322323
const context = Object.assign({}, fakeContext,
323324
{ settings: {

tests/src/core/parse.js

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ describe('parse(content, { settings, ecmaFeatures })', function () {
3838
.that.is.eql(parserOptions.ecmaFeatures)
3939
.and.is.not.equal(parserOptions.ecmaFeatures)
4040
expect(parseSpy.args[0][1], 'custom parser to get parserOptions.attachComment equal to true').to.have.property('attachComment', true)
41+
expect(parseSpy.args[0][1], 'custom parser to get parserOptions.tokens equal to true').to.have.property('tokens', true)
42+
expect(parseSpy.args[0][1], 'custom parser to get parserOptions.range equal to true').to.have.property('range', true)
4143
expect(parseSpy.args[0][1], 'custom parser to get parserOptions.filePath equal to the full path of the source file').to.have.property('filePath', path)
4244
})
4345

0 commit comments

Comments
 (0)