Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deps, fix tests #1254

Merged
merged 9 commits into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ matrix:
node_js: 6
- env: PACKAGE=resolvers/webpack
node_js: 4

- os: osx
env: ESLINT_VERSION=5
node_js: 10
Expand All @@ -44,16 +45,23 @@ matrix:
- os: osx
env: ESLINT_VERSION=2
node_js: 4

exclude:
- node_js: '4'
env: ESLINT_VERSION=5

fast_finish: true
allow_failures:
# issues with typescript deps in this version intersection
- node_js: '4'
env: ESLINT_VERSION=4

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

script:
- 'npm test'
Expand Down
9 changes: 5 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ environment:
matrix:
- nodejs_version: "10"
- nodejs_version: "8"
- nodejs_version: "6"
- nodejs_version: "4"
# - nodejs_version: "6"
# - nodejs_version: "4"

matrix:
fast_finish: true
allow_failures:
- nodejs_version: "4" # for eslint 5

# allow_failures:
# - nodejs_version: "4" # for eslint 5

# platform:
# - x86
Expand Down
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,45 +44,45 @@
},
"homepage": "https://github.com/benmosher/eslint-plugin-import",
"devDependencies": {
"babel-eslint": "8.0.x",
"babel-eslint": "^8.2.6",
"babel-plugin-istanbul": "^4.1.6",
"babel-preset-es2015-argon": "latest",
"babel-register": "^6.26.0",
"babylon": "6.15.0",
"babylon": "^6.15.0",
"chai": "^3.5.0",
"coveralls": "^3.0.0",
"coveralls": "^3.0.2",
"cross-env": "^4.0.0",
"eslint": "2.x - 5.x",
"eslint-import-resolver-node": "file:./resolvers/node",
"eslint-import-resolver-typescript": "1.0.2",
"eslint-import-resolver-typescript": "^1.0.2",
"eslint-import-resolver-webpack": "file:./resolvers/webpack",
"eslint-module-utils": "file:./utils",
"eslint-plugin-import": "2.x",
"gulp": "^3.9.0",
"gulp": "^3.9.1",
"gulp-babel": "6.1.2",
"linklocal": "^2.6.0",
"linklocal": "^2.8.2",
"mocha": "^3.5.3",
"nyc": "^11.7.1",
"redux": "^3.0.4",
"rimraf": "^2.6.2",
"sinon": "^2.3.2",
"typescript": "~2.8.1",
"typescript-eslint-parser": "^15.0.0"
"nyc": "^11.9.0",
"redux": "^3.7.2",
"rimraf": "^2.6.3",
"sinon": "^2.4.1",
"typescript": "^3.2.2",
"typescript-eslint-parser": "^21.0.2"
},
"peerDependencies": {
"eslint": "2.x - 5.x"
},
"dependencies": {
"contains-path": "^0.1.0",
"debug": "^2.6.8",
"debug": "^2.6.9",
"doctrine": "1.5.0",
"eslint-import-resolver-node": "^0.3.1",
"eslint-import-resolver-node": "^0.3.2",
"eslint-module-utils": "^2.2.0",
"has": "^1.0.1",
"lodash": "^4.17.4",
"minimatch": "^3.0.3",
"has": "^1.0.3",
"lodash": "^4.17.11",
"minimatch": "^3.0.4",
"read-pkg-up": "^2.0.0",
"resolve": "^1.6.0"
"resolve": "^1.9.0"
},
"nyc": {
"require": [
Expand Down
48 changes: 36 additions & 12 deletions src/ExportMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import doctrine from 'doctrine'

import debug from 'debug'

import SourceCode from 'eslint/lib/util/source-code'

import parse from 'eslint-module-utils/parse'
import resolve from 'eslint-module-utils/resolve'
import isIgnored, { hasValidExtension } from 'eslint-module-utils/ignore'
Expand Down Expand Up @@ -193,22 +195,28 @@ export default class ExportMap {
* @param {...[type]} nodes [description]
* @return {{doc: object}}
*/
function captureDoc(docStyleParsers) {
function captureDoc(source, docStyleParsers) {
const metadata = {}
, nodes = Array.prototype.slice.call(arguments, 1)

// 'some' short-circuits on first 'true'
nodes.some(n => {
if (!n.leadingComments) return false

for (let name in docStyleParsers) {
const doc = docStyleParsers[name](n.leadingComments)
if (doc) {
metadata.doc = doc
try {
// n.leadingComments is legacy `attachComments` behavior
let leadingComments = n.leadingComments || source.getCommentsBefore(n)
if (leadingComments.length === 0) return false

for (let name in docStyleParsers) {
const doc = docStyleParsers[name](leadingComments)
if (doc) {
metadata.doc = doc
}
}
}

return true
return true
} catch (err) {
return false
}
})

return metadata
Expand Down Expand Up @@ -338,6 +346,8 @@ ExportMap.parse = function (path, content, context) {
docStyleParsers[style] = availableDocStyleParsers[style]
})

const source = makeSourceCode(content, ast)

// attempt to collect module doc
if (ast.comments) {
ast.comments.some(c => {
Expand Down Expand Up @@ -405,7 +415,7 @@ ExportMap.parse = function (path, content, context) {
ast.body.forEach(function (n) {

if (n.type === 'ExportDefaultDeclaration') {
const exportMeta = captureDoc(docStyleParsers, n)
const exportMeta = captureDoc(source, docStyleParsers, n)
if (n.declaration.type === 'Identifier') {
addNamespace(exportMeta, n.declaration)
}
Expand Down Expand Up @@ -441,12 +451,12 @@ ExportMap.parse = function (path, content, context) {
case 'TSInterfaceDeclaration':
case 'TSAbstractClassDeclaration':
case 'TSModuleDeclaration':
m.namespace.set(n.declaration.id.name, captureDoc(docStyleParsers, n))
m.namespace.set(n.declaration.id.name, captureDoc(source, docStyleParsers, n))
break
case 'VariableDeclaration':
n.declaration.declarations.forEach((d) =>
recursivePatternCapture(d.id,
id => m.namespace.set(id.name, captureDoc(docStyleParsers, d, n))))
id => m.namespace.set(id.name, captureDoc(source, docStyleParsers, d, n))))
break
}
}
Expand Down Expand Up @@ -531,3 +541,17 @@ function childContext(path, context) {
path,
}
}


/**
* sometimes legacy support isn't _that_ hard... right?
*/
function makeSourceCode(text, ast) {
if (SourceCode.length > 1) {
// ESLint 3
return new SourceCode(text, ast)
} else {
// ESLint 4, 5
return new SourceCode({ text, ast })
}
}
44 changes: 21 additions & 23 deletions src/rules/no-amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,33 @@ import docsUrl from '../docsUrl'
//------------------------------------------------------------------------------

module.exports = {
meta: {
type: 'suggestion',
docs: {
url: docsUrl('no-amd'),
},
meta: {
type: 'suggestion',
docs: {
url: docsUrl('no-amd'),
},
},

create: function (context) {
create: function (context) {
return {
'CallExpression': function (node) {
if (context.getScope().type !== 'module') return

return {
if (node.callee.type !== 'Identifier') return
if (node.callee.name !== 'require' &&
node.callee.name !== 'define') return

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

if (node.callee.type !== 'Identifier') return
if (node.callee.name !== 'require' &&
node.callee.name !== 'define') return
const modules = node.arguments[0]
if (modules.type !== 'ArrayExpression') return

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

const modules = node.arguments[0]
if (modules.type !== 'ArrayExpression') return
context.report(node, `Expected imports instead of AMD ${node.callee.name}().`)
},
}

// todo: check second arg type? (identifier or callback)

context.report(node, `Expected imports instead of AMD ${node.callee.name}().`)
},
}

},
},
}
20 changes: 20 additions & 0 deletions tests/dep-time-travel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# expected: ESLINT_VERSION numeric env var

npm install --no-save eslint@$ESLINT_VERSION --ignore-scripts || true
ljharb marked this conversation as resolved.
Show resolved Hide resolved

# use these alternate typescript dependencies for ESLint < v4
if [[ "$ESLINT_VERSION" -lt "4" ]]; then
echo "Downgrading babel-eslint..."
npm i --no-save babel-eslint@8.0.3

echo "Downgrading TypeScript dependencies..."
npm i --no-save typescript-eslint-parser@15 typescript@2.8.1
fi

# typescript-eslint-parser 1.1.1+ is not compatible with node 6
if [[ "$TRAVIS_NODE_VERSION" -lt "8" ]]; then
echo "Downgrading eslint-import-resolver-typescript..."
npm i --no-save eslint-import-resolver-typescript@1.0.2
fi
6 changes: 3 additions & 3 deletions tests/files/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ export const MY_TERRIBLE_ACTION = "ugh"
* @deprecated this chain is awful
* @type {String}
*/
export const CHAIN_A = "a"
export const CHAIN_A = "a",
/**
* @deprecated so awful
* @type {String}
*/
, CHAIN_B = "b"
CHAIN_B = "b",

/**
* @deprecated still terrible
* @type {String}
*/
, CHAIN_C = "C"
CHAIN_C = "C"

/**
* this one is fine
Expand Down
1 change: 1 addition & 0 deletions tests/src/core/getExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ describe('ExportMap', function () {
]

configs.forEach(([description, parserConfig]) => {

describe(description, function () {
const context = Object.assign({}, fakeContext,
{ settings: {
Expand Down
2 changes: 2 additions & 0 deletions tests/src/core/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ describe('parse(content, { settings, ecmaFeatures })', function () {
.that.is.eql(parserOptions.ecmaFeatures)
.and.is.not.equal(parserOptions.ecmaFeatures)
expect(parseSpy.args[0][1], 'custom parser to get parserOptions.attachComment equal to true').to.have.property('attachComment', true)
expect(parseSpy.args[0][1], 'custom parser to get parserOptions.tokens equal to true').to.have.property('tokens', true)
expect(parseSpy.args[0][1], 'custom parser to get parserOptions.range equal to true').to.have.property('range', true)
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)
})

Expand Down
Loading