From d290a87dd6e10227c5f352bd05dee0fb361cd5a6 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 3 Jan 2019 11:19:03 -0800 Subject: [PATCH 1/9] [Dev Deps] update `babylon`, `coveralls`, `eslint-import-resolver-typescript`, `gulp`, `linklocal`, `nyc`, `redux`, `rimraf`, `sinon`, `typescript-eslint-parser` --- package.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 4f3722a95..7dfe80350 100644 --- a/package.json +++ b/package.json @@ -48,26 +48,26 @@ "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", + "nyc": "^11.9.0", + "redux": "^3.7.2", + "rimraf": "^2.6.3", + "sinon": "^2.4.1", "typescript": "~2.8.1", - "typescript-eslint-parser": "^15.0.0" + "typescript-eslint-parser": "^21.0.2" }, "peerDependencies": { "eslint": "2.x - 5.x" From cf1f6f46f7d0fd6a9532c51d44d12ae08447cffd Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 3 Jan 2019 11:22:23 -0800 Subject: [PATCH 2/9] [Deps] update `debug`, `eslint-import-resolver-node`, `has`, `lodash`, `minimatch`, `resolve` --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 7dfe80350..dd5405533 100644 --- a/package.json +++ b/package.json @@ -74,15 +74,15 @@ }, "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": [ From b686f9d823c417e98a824c4ff6bfd65c1582ec45 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Mon, 14 Jan 2019 21:10:11 -0500 Subject: [PATCH 3/9] drop ESLint 2/3 from Travis/Appveyor because Typescript parser can't deal --- .travis.yml | 19 +++++++++++-------- appveyor.yml | 9 +++++---- package.json | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index ea8c60a59..03de81c6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,8 @@ os: linux env: - ESLINT_VERSION=5 - ESLINT_VERSION=4 - - ESLINT_VERSION=3 - - ESLINT_VERSION=2 + # - ESLINT_VERSION=3 + # - ESLINT_VERSION=2 # osx backlog is often deep, so to be polite we can just hit these highlights matrix: @@ -38,12 +38,15 @@ matrix: - os: osx env: ESLINT_VERSION=4 node_js: 8 - - os: osx - env: ESLINT_VERSION=3 - node_js: 6 - - os: osx - env: ESLINT_VERSION=2 - node_js: 4 + + # the following combos fail TypeScript tests + # - os: osx + # env: ESLINT_VERSION=3 + # node_js: 6 + # - os: osx + # env: ESLINT_VERSION=2 + # node_js: 4 + exclude: - node_js: '4' env: ESLINT_VERSION=5 diff --git a/appveyor.yml b/appveyor.yml index 0176e1254..bb435695f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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 diff --git a/package.json b/package.json index dd5405533..58618e233 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "redux": "^3.7.2", "rimraf": "^2.6.3", "sinon": "^2.4.1", - "typescript": "~2.8.1", + "typescript": "^3.2.2", "typescript-eslint-parser": "^21.0.2" }, "peerDependencies": { From acfb6e926f9324210d71ce1c8d453d17d707a9bd Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Mon, 14 Jan 2019 21:54:12 -0500 Subject: [PATCH 4/9] jk, test against eslint 2/3 but skip Typescript tests. also bumped babel-eslint --- .travis.yml | 18 +-- package.json | 2 +- src/rules/no-amd.js | 44 +++--- tests/src/core/getExports.js | 5 +- tests/src/rules/named.js | 190 ++++++++++++------------ tests/src/rules/newline-after-import.js | 3 +- tests/src/utils.js | 11 ++ 7 files changed, 146 insertions(+), 127 deletions(-) diff --git a/.travis.yml b/.travis.yml index 03de81c6d..75f2e67ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,8 @@ os: linux env: - ESLINT_VERSION=5 - ESLINT_VERSION=4 - # - ESLINT_VERSION=3 - # - ESLINT_VERSION=2 + - ESLINT_VERSION=3 + - ESLINT_VERSION=2 # osx backlog is often deep, so to be polite we can just hit these highlights matrix: @@ -38,14 +38,12 @@ matrix: - os: osx env: ESLINT_VERSION=4 node_js: 8 - - # the following combos fail TypeScript tests - # - os: osx - # env: ESLINT_VERSION=3 - # node_js: 6 - # - os: osx - # env: ESLINT_VERSION=2 - # node_js: 4 + - os: osx + env: ESLINT_VERSION=3 + node_js: 6 + - os: osx + env: ESLINT_VERSION=2 + node_js: 4 exclude: - node_js: '4' diff --git a/package.json b/package.json index 58618e233..fd0ead0c8 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ }, "homepage": "https://github.com/benmosher/eslint-plugin-import", "devDependencies": { - "babel-eslint": "8.0.x", + "babel-eslint": "^10.0.1", "babel-plugin-istanbul": "^4.1.6", "babel-preset-es2015-argon": "latest", "babel-register": "^6.26.0", diff --git a/src/rules/no-amd.js b/src/rules/no-amd.js index df0d3aeb2..394244341 100644 --- a/src/rules/no-amd.js +++ b/src/rules/no-amd.js @@ -10,35 +10,35 @@ 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 { + console.log("got scope", context.getScope().type) - 'CallExpression': function (node) { - if (context.getScope().type !== 'module') return + if (node.callee.type !== 'Identifier') return + if (node.callee.name !== 'require' && + node.callee.name !== 'define') return - if (node.callee.type !== 'Identifier') return - if (node.callee.name !== 'require' && - node.callee.name !== 'define') return + // todo: capture define((require, module, exports) => {}) form? + if (node.arguments.length !== 2) return - // todo: capture define((require, module, exports) => {}) form? - if (node.arguments.length !== 2) return + const modules = node.arguments[0] + if (modules.type !== 'ArrayExpression') return - const modules = node.arguments[0] - if (modules.type !== 'ArrayExpression') return + // todo: check second arg type? (identifier or callback) - // todo: check second arg type? (identifier or callback) + context.report(node, `Expected imports instead of AMD ${node.callee.name}().`) + }, + } - context.report(node, `Expected imports instead of AMD ${node.callee.name}().`) - }, - } - - }, + }, } diff --git a/tests/src/core/getExports.js b/tests/src/core/getExports.js index 3bda3d3db..b33d548f0 100644 --- a/tests/src/core/getExports.js +++ b/tests/src/core/getExports.js @@ -3,7 +3,7 @@ import ExportMap from '../../../src/ExportMap' import * as fs from 'fs' -import { getFilename } from '../utils' +import { getFilename, skipESLints } from '../utils' import * as unambiguous from 'eslint-module-utils/unambiguous' describe('ExportMap', function () { @@ -310,7 +310,7 @@ describe('ExportMap', function () { }) - context('alternate parsers', function () { + skipESLints([2, 3])('alternate parsers', function () { const configs = [ // ['string form', { 'typescript-eslint-parser': '.ts' }], @@ -318,6 +318,7 @@ describe('ExportMap', function () { ] configs.forEach(([description, parserConfig]) => { + describe(description, function () { const context = Object.assign({}, fakeContext, { settings: { diff --git a/tests/src/rules/named.js b/tests/src/rules/named.js index ed6dc9e04..7ffd929e1 100644 --- a/tests/src/rules/named.js +++ b/tests/src/rules/named.js @@ -1,4 +1,4 @@ -import { test, SYNTAX_CASES } from '../utils' +import { test, SYNTAX_CASES, skipESLints } from '../utils' import { RuleTester } from 'eslint' import { CASE_SENSITIVE_FS } from 'eslint-module-utils/resolve' @@ -83,70 +83,6 @@ ruleTester.run('named', rule, { parser: 'babel-eslint', }), - // TypeScript - test({ - code: 'import { MyType } from "./typescript"', - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - }), - test({ - code: 'import { Foo } from "./typescript"', - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - }), - test({ - code: 'import { Bar } from "./typescript"', - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - }), - test({ - code: 'import { getFoo } from "./typescript"', - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - }), - test({ - code: 'import { MyEnum } from "./typescript"', - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - }), - test({ - code: ` - import { MyModule } from "./typescript" - MyModule.ModuleFunction() - `, - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - }), - test({ - code: ` - import { MyNamespace } from "./typescript" - MyNamespace.NSModule.NSModuleFunction() - `, - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - }), - // jsnext test({ code: '/*jsnext*/ import { createStore } from "redux"', @@ -246,32 +182,6 @@ ruleTester.run('named', rule, { // }], // }), - // TypeScript - test({ - code: 'import { MissingType } from "./typescript"', - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - errors: [{ - message: "MissingType not found in './typescript'", - type: 'Identifier', - }], - }), - test({ - code: 'import { NotExported } from "./typescript"', - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - errors: [{ - message: "NotExported not found in './typescript'", - type: 'Identifier', - }], - }), - test({ code: 'import { type MyOpaqueType, MyMissingClass } from "./flowtypes"', parser: 'babel-eslint', @@ -342,3 +252,101 @@ ruleTester.run('named (export *)', rule, { }), ], }) + + +skipESLints([2, 3])("Typescript", function () { + // Typescript + ruleTester.run("named", rule, { + valid: [ + test({ + code: 'import { MyType } from "./typescript"', + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + }), + test({ + code: 'import { Foo } from "./typescript"', + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + }), + test({ + code: 'import { Bar } from "./typescript"', + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + }), + test({ + code: 'import { getFoo } from "./typescript"', + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + }), + test({ + code: 'import { MyEnum } from "./typescript"', + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + }), + test({ + code: ` + import { MyModule } from "./typescript" + MyModule.ModuleFunction() + `, + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + }), + test({ + code: ` + import { MyNamespace } from "./typescript" + MyNamespace.NSModule.NSModuleFunction() + `, + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + }), + ], + + invalid: [ + test({ + code: 'import { MissingType } from "./typescript"', + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + errors: [{ + message: "MissingType not found in './typescript'", + type: 'Identifier', + }], + }), + test({ + code: 'import { NotExported } from "./typescript"', + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + errors: [{ + message: "NotExported not found in './typescript'", + type: 'Identifier', + }], + }), + ] + }) +}) diff --git a/tests/src/rules/newline-after-import.js b/tests/src/rules/newline-after-import.js index 00ebfa432..730cef363 100644 --- a/tests/src/rules/newline-after-import.js +++ b/tests/src/rules/newline-after-import.js @@ -153,8 +153,9 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), { }, { code: `//issue 592 + export default @SomeDecorator(require('./some-file')) - export default class App {} + class App {} `, parserOptions: { sourceType: 'module' }, parser: 'babel-eslint', diff --git a/tests/src/utils.js b/tests/src/utils.js index fe04d684e..9ec1b3e48 100644 --- a/tests/src/utils.js +++ b/tests/src/utils.js @@ -29,6 +29,17 @@ export function getFilename(file) { return path.join(__dirname, '..', 'files', file || 'foo.js') } +/** + * skip tests iff ESLINT_VERSION is in provided `versions` array + */ +export function skipESLints(versions) { + if (!versions.includes(+process.env.ESLINT_VERSION)) { + return describe + } else { + return describe.skip + } +} + /** * to be added as valid cases just to ensure no nullable fields are going * to crash at runtime From f16523728a32f185058e50c5f7348a9d0bf69d1f Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Mon, 14 Jan 2019 22:00:07 -0500 Subject: [PATCH 5/9] ah geez, bumping babel-eslint breaks no-amd/no-cjs also left my debug console in :-( --- package.json | 2 +- src/rules/no-amd.js | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/package.json b/package.json index fd0ead0c8..f13598aa8 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ }, "homepage": "https://github.com/benmosher/eslint-plugin-import", "devDependencies": { - "babel-eslint": "^10.0.1", + "babel-eslint": "^8.2.6", "babel-plugin-istanbul": "^4.1.6", "babel-preset-es2015-argon": "latest", "babel-register": "^6.26.0", diff --git a/src/rules/no-amd.js b/src/rules/no-amd.js index 394244341..bb7c8ed82 100644 --- a/src/rules/no-amd.js +++ b/src/rules/no-amd.js @@ -22,8 +22,6 @@ module.exports = { 'CallExpression': function (node) { if (context.getScope().type !== 'module') return - console.log("got scope", context.getScope().type) - if (node.callee.type !== 'Identifier') return if (node.callee.name !== 'require' && node.callee.name !== 'define') return From 10c981163c3970b5633c1fd4d812b8f65790f6d8 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Mon, 14 Jan 2019 22:16:00 -0500 Subject: [PATCH 6/9] node 4 fix for test util --- tests/src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/utils.js b/tests/src/utils.js index 9ec1b3e48..56e8ab72a 100644 --- a/tests/src/utils.js +++ b/tests/src/utils.js @@ -33,7 +33,7 @@ export function getFilename(file) { * skip tests iff ESLINT_VERSION is in provided `versions` array */ export function skipESLints(versions) { - if (!versions.includes(+process.env.ESLINT_VERSION)) { + if (versions.indexOf(+process.env.ESLINT_VERSION) === -1) { return describe } else { return describe.skip From 05c3935048577bd7b025d6b833d8503807f02189 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Wed, 16 Jan 2019 07:18:43 -0500 Subject: [PATCH 7/9] repair `no-deprecated` for ESLint* 5 * technically espree v5 - also technically it doesn't support comma-first anymore but that seems reasonable --- src/ExportMap.js | 48 +++++++++++++++++++++++++++++---------- tests/files/deprecated.js | 6 ++--- tests/src/core/parse.js | 2 ++ utils/parse.js | 6 +++-- 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/ExportMap.js b/src/ExportMap.js index 563ff9e8c..c8335d9c8 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -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' @@ -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 @@ -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 => { @@ -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) } @@ -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 } } @@ -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 }) + } +} diff --git a/tests/files/deprecated.js b/tests/files/deprecated.js index 10e81dc91..f5229f59b 100644 --- a/tests/files/deprecated.js +++ b/tests/files/deprecated.js @@ -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 diff --git a/tests/src/core/parse.js b/tests/src/core/parse.js index 9cc153ae3..4b0f12c62 100644 --- a/tests/src/core/parse.js +++ b/tests/src/core/parse.js @@ -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) }) diff --git a/utils/parse.js b/utils/parse.js index 5bafdba49..2946047ad 100644 --- a/utils/parse.js +++ b/utils/parse.js @@ -19,12 +19,14 @@ exports.default = function parse(path, content, context) { parserOptions = Object.assign({}, parserOptions) parserOptions.ecmaFeatures = Object.assign({}, parserOptions.ecmaFeatures) - // always include and attach comments + // always include comments and tokens (for doc parsing) parserOptions.comment = true - parserOptions.attachComment = true + parserOptions.attachComment = true // keeping this for backward-compat with older parsers + parserOptions.tokens = true // attach node locations parserOptions.loc = true + parserOptions.range = true // provide the `filePath` like eslint itself does, in `parserOptions` // https://github.com/eslint/eslint/blob/3ec436ee/lib/linter.js#L637 From 73080d0ba88b55b0794d288f8ef4f476873c3367 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Thu, 17 Jan 2019 06:09:54 -0500 Subject: [PATCH 8/9] dep-time-travel: use older versions of dependencies for tests against older ESLint versions. --- .travis.yml | 3 ++- tests/dep-time-travel.sh | 20 ++++++++++++++++++++ tests/src/core/getExports.js | 4 ++-- tests/src/rules/named.js | 4 ++-- tests/src/utils.js | 11 ----------- 5 files changed, 26 insertions(+), 16 deletions(-) create mode 100755 tests/dep-time-travel.sh diff --git a/.travis.yml b/.travis.yml index 75f2e67ad..c359e7371 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,6 +32,7 @@ matrix: node_js: 6 - env: PACKAGE=resolvers/webpack node_js: 4 + - os: osx env: ESLINT_VERSION=5 node_js: 10 @@ -54,7 +55,7 @@ before_install: - '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' diff --git a/tests/dep-time-travel.sh b/tests/dep-time-travel.sh new file mode 100755 index 000000000..eae24998d --- /dev/null +++ b/tests/dep-time-travel.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# expected: ESLINT_VERSION numeric env var + +npm install --no-save eslint@$ESLINT_VERSION --ignore-scripts || true + +# 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 diff --git a/tests/src/core/getExports.js b/tests/src/core/getExports.js index b33d548f0..8e01f62ac 100644 --- a/tests/src/core/getExports.js +++ b/tests/src/core/getExports.js @@ -3,7 +3,7 @@ import ExportMap from '../../../src/ExportMap' import * as fs from 'fs' -import { getFilename, skipESLints } from '../utils' +import { getFilename } from '../utils' import * as unambiguous from 'eslint-module-utils/unambiguous' describe('ExportMap', function () { @@ -310,7 +310,7 @@ describe('ExportMap', function () { }) - skipESLints([2, 3])('alternate parsers', function () { + context('alternate parsers', function () { const configs = [ // ['string form', { 'typescript-eslint-parser': '.ts' }], diff --git a/tests/src/rules/named.js b/tests/src/rules/named.js index 7ffd929e1..92b3d9163 100644 --- a/tests/src/rules/named.js +++ b/tests/src/rules/named.js @@ -1,4 +1,4 @@ -import { test, SYNTAX_CASES, skipESLints } from '../utils' +import { test, SYNTAX_CASES } from '../utils' import { RuleTester } from 'eslint' import { CASE_SENSITIVE_FS } from 'eslint-module-utils/resolve' @@ -254,7 +254,7 @@ ruleTester.run('named (export *)', rule, { }) -skipESLints([2, 3])("Typescript", function () { +context("Typescript", function () { // Typescript ruleTester.run("named", rule, { valid: [ diff --git a/tests/src/utils.js b/tests/src/utils.js index 56e8ab72a..fe04d684e 100644 --- a/tests/src/utils.js +++ b/tests/src/utils.js @@ -29,17 +29,6 @@ export function getFilename(file) { return path.join(__dirname, '..', 'files', file || 'foo.js') } -/** - * skip tests iff ESLINT_VERSION is in provided `versions` array - */ -export function skipESLints(versions) { - if (versions.indexOf(+process.env.ESLINT_VERSION) === -1) { - return describe - } else { - return describe.skip - } -} - /** * to be added as valid cases just to ensure no nullable fields are going * to crash at runtime From 64d9be7d76aa7a901d846f08a3342b98b0c3d809 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Fri, 18 Jan 2019 20:03:36 -0500 Subject: [PATCH 9/9] allow_failures for dicey Node/ESLint intersection --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index c359e7371..e8eaf9d96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,6 +49,12 @@ matrix: 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'