diff --git a/.github/workflows/node-4+.yml b/.github/workflows/node-4+.yml index 6456762fce..b4223f900f 100644 --- a/.github/workflows/node-4+.yml +++ b/.github/workflows/node-4+.yml @@ -26,6 +26,7 @@ jobs: matrix: node-version: ${{ fromJson(needs.matrix.outputs.latest) }} eslint: + - ^8.0.0-0 - 7 - 6 - 5 @@ -39,24 +40,44 @@ jobs: env: TS_PARSER: 2 exclude: + - node-version: 15 + eslint: ^8.0.0-0 + - node-version: 13 + eslint: ^8.0.0-0 + - node-version: 11 + eslint: ^8.0.0-0 + - node-version: 10 + eslint: ^8.0.0-0 + - node-version: 9 + eslint: ^8.0.0-0 - node-version: 9 eslint: 7 + - node-version: 8 + eslint: ^8.0.0-0 - node-version: 8 eslint: 7 + - node-version: 7 + eslint: ^8.0.0-0 - node-version: 7 eslint: 7 - node-version: 7 eslint: 6 + - node-version: 6 + eslint: ^8.0.0-0 - node-version: 6 eslint: 7 - node-version: 6 eslint: 6 + - node-version: 5 + eslint: ^8.0.0-0 - node-version: 5 eslint: 7 - node-version: 5 eslint: 6 - node-version: 5 eslint: 5 + - node-version: 4 + eslint: ^8.0.0-0 - node-version: 4 eslint: 7 - node-version: 4 diff --git a/package.json b/package.json index e3bc5a8d96..c6604223c5 100644 --- a/package.json +++ b/package.json @@ -69,9 +69,11 @@ "babel-register": "^6.26.0", "babylon": "^6.18.0", "chai": "^4.3.4", + "chai-as-promised": "^7.1.1", "coveralls": "^3.1.0", "cross-env": "^4.0.0", - "eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0", + "escope": "^3.6.0", + "eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8.0.0-0", "eslint-import-resolver-node": "file:./resolvers/node", "eslint-import-resolver-typescript": "^1.0.2 || ^1.1.1", "eslint-import-resolver-webpack": "file:./resolvers/webpack", diff --git a/src/rules/no-unused-modules.js b/src/rules/no-unused-modules.js index d49674e7e5..f0348773f5 100644 --- a/src/rules/no-unused-modules.js +++ b/src/rules/no-unused-modules.js @@ -15,9 +15,17 @@ import includes from 'array-includes'; // eslint/lib/util/glob-util has been moved to eslint/lib/util/glob-utils with version 5.3 // and has been moved to eslint/lib/cli-engine/file-enumerator in version 6 +// and has been moved to eslint/use-at-your-own-risk in version 8 let listFilesToProcess; try { - const FileEnumerator = require('eslint/lib/cli-engine/file-enumerator').FileEnumerator; + // eslint/lib/cli-engine/file-enumerator has been moved to eslint/use-at-your-own-risk + // in version 8 + let FileEnumerator; + try { + FileEnumerator = require('eslint/use-at-your-own-risk').FileEnumerator; + } catch (e) { + FileEnumerator = require('eslint/lib/cli-engine/file-enumerator').FileEnumerator; + } listFilesToProcess = function (src, extensions) { const e = new FileEnumerator({ extensions: extensions, @@ -228,7 +236,7 @@ const prepareImportsAndExports = (srcFiles, context) => { } const localImport = imports.get(key) || new Set(); value.declarations.forEach(({ importedSpecifiers }) => - importedSpecifiers.forEach(specifier => localImport.add(specifier)) + importedSpecifiers.forEach(specifier => localImport.add(specifier)), ); imports.set(key, localImport); }); @@ -544,13 +552,13 @@ module.exports = { if (exportStatement.whereUsed.size < 1) { context.report( node, - `exported declaration '${value}' not used within other modules` + `exported declaration '${value}' not used within other modules`, ); } } else { context.report( node, - `exported declaration '${value}' not used within other modules` + `exported declaration '${value}' not used within other modules`, ); } }; diff --git a/tests/dep-time-travel.sh b/tests/dep-time-travel.sh index ad00568e4c..761dae9349 100755 --- a/tests/dep-time-travel.sh +++ b/tests/dep-time-travel.sh @@ -8,19 +8,23 @@ export NPM_CONFIG_LEGACY_PEER_DEPS=true npm install --no-save "eslint@${ESLINT_VERSION}" --ignore-scripts -# completely remove the new TypeScript parser for ESLint < v5 -if [[ "$ESLINT_VERSION" -lt "5" ]]; then - echo "Removing @typescript-eslint/parser..." - npm uninstall --no-save @typescript-eslint/parser -fi - -# 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 +re="^[0-9]+$" + +if [[ "$ESLINT_VERSION" =~ $re ]] ; then + # completely remove the new TypeScript parser for ESLint < v5 + if [[ "$ESLINT_VERSION" -lt "5" ]]; then + echo "Removing @typescript-eslint/parser..." + npm uninstall --no-save @typescript-eslint/parser + fi + + # 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 fi # typescript-eslint-parser 1.1.1+ is not compatible with node 6 diff --git a/tests/src/cli.js b/tests/src/cli.js index 91d3dfc158..6e70b41388 100644 --- a/tests/src/cli.js +++ b/tests/src/cli.js @@ -3,82 +3,107 @@ */ import path from 'path'; -import { expect } from 'chai'; -import { CLIEngine } from 'eslint'; +import { expect, use } from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import { CLIEngine, ESLint as ESLintClass } from 'eslint'; import eslintPkg from 'eslint/package.json'; import semver from 'semver'; +import * as importPlugin from '../../src/index'; + +use(chaiAsPromised); + +const ESLint = ESLintClass || class { + constructor(options) { + options = Object.assign({},options); + const overrideConfig = options.overrideConfig; + delete options.overrideConfig; + const overrideConfigFile = options.overrideConfigFile; + delete options.overrideConfigFile; + const pluginsMap = options.plugins; + delete options.plugins; + this.engine = new CLIEngine(Object.assign(options, overrideConfig, overrideConfigFile ? { configFile:overrideConfigFile }: {})); + + for (const [name, plugin] of Object.entries(pluginsMap || {})) { + this.engine.addPlugin(name, plugin); + } + } + lintFiles(params) { + const result = this.engine.executeOnFiles(params); + return Promise.resolve(result.results); + } +}; describe('CLI regression tests', function () { describe('issue #210', function () { - let cli; + let eslint; before(function () { - cli = new CLIEngine({ + eslint = new ESLint({ useEslintrc: false, - configFile: './tests/files/issue210.config.js', + overrideConfigFile: './tests/files/issue210.config.js', rulePaths: ['./src/rules'], - rules: { - 'named': 2, + overrideConfig: { + rules: { + 'named': 2, + }, }, + plugins: { 'eslint-plugin-import': importPlugin }, }); }); it("doesn't throw an error on gratuitous, erroneous self-reference", function () { - expect(() => cli.executeOnFiles(['./tests/files/issue210.js'])).not.to.throw(); + return expect(eslint.lintFiles(['./tests/files/issue210.js'])).not.to.rejected; }); }); describe('issue #1645', function () { - let cli; + let eslint; beforeEach(function () { if (semver.satisfies(eslintPkg.version, '< 6')) { this.skip(); } else { - cli = new CLIEngine({ + eslint = new ESLint({ useEslintrc: false, - configFile: './tests/files/just-json-files/.eslintrc.json', + overrideConfigFile: './tests/files/just-json-files/.eslintrc.json', rulePaths: ['./src/rules'], ignore: false, + plugins: { 'eslint-plugin-import': importPlugin }, }); } }); it('throws an error on invalid JSON', () => { const invalidJSON = './tests/files/just-json-files/invalid.json'; - const results = cli.executeOnFiles([invalidJSON]); - expect(results).to.eql({ - results: [ - { - filePath: path.resolve(invalidJSON), - messages: [ - { - column: 2, - endColumn: 3, - endLine: 1, - line: 1, - message: 'Expected a JSON object, array or literal.', - nodeType: results.results[0].messages[0].nodeType, // we don't care about this one - ruleId: 'json/*', - severity: 2, - source: results.results[0].messages[0].source, // NewLine-characters might differ depending on git-settings - }, - ], - errorCount: 1, - ...(semver.satisfies(eslintPkg.version, '>= 7.32') && { - fatalErrorCount: 0, - }), - warningCount: 0, - fixableErrorCount: 0, - fixableWarningCount: 0, - source: results.results[0].source, // NewLine-characters might differ depending on git-settings - }, - ], - ...(semver.satisfies(eslintPkg.version, '>= 7.32') && { - fatalErrorCount: 0, - }), - errorCount: 1, - warningCount: 0, - fixableErrorCount: 0, - fixableWarningCount: 0, - usedDeprecatedRules: results.usedDeprecatedRules, // we don't care about this one + return eslint.lintFiles([invalidJSON]).then(results => { + expect(results).to.eql( + [ + { + filePath: path.resolve(invalidJSON), + messages: [ + { + column: 2, + endColumn: 3, + endLine: 1, + line: 1, + message: 'Expected a JSON object, array or literal.', + nodeType: results[0].messages[0].nodeType, // we don't care about this one + ruleId: 'json/*', + severity: 2, + source: results[0].messages[0].source, // NewLine-characters might differ depending on git-settings + }, + ], + errorCount: 1, + ...(semver.satisfies(eslintPkg.version, '>= 7.32 || ^8.0.0-0') && { + fatalErrorCount: 0, + }), + warningCount: 0, + fixableErrorCount: 0, + fixableWarningCount: 0, + source: results[0].source, // NewLine-characters might differ depending on git-settings + ...(semver.satisfies(eslintPkg.version, '>= 7.0.0') && { + usedDeprecatedRules: results[0].usedDeprecatedRules, // we don't care about this one + }), + }, + ], + ); }); }); }); diff --git a/tests/src/rules/no-amd.js b/tests/src/rules/no-amd.js index 74c89c4116..91e29234c8 100644 --- a/tests/src/rules/no-amd.js +++ b/tests/src/rules/no-amd.js @@ -2,7 +2,7 @@ import { RuleTester } from 'eslint'; import eslintPkg from 'eslint/package.json'; import semver from 'semver'; -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015, sourceType: 'module' } }); ruleTester.run('no-amd', require('rules/no-amd'), { valid: [ diff --git a/tests/src/rules/no-commonjs.js b/tests/src/rules/no-commonjs.js index b1d8c03c1d..a2e3464ca7 100644 --- a/tests/src/rules/no-commonjs.js +++ b/tests/src/rules/no-commonjs.js @@ -5,7 +5,7 @@ import semver from 'semver'; const EXPORT_MESSAGE = 'Expected "export" or "export default"'; const IMPORT_MESSAGE = 'Expected "import" instead of "require()"'; -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015, sourceType: 'module' } }); ruleTester.run('no-commonjs', require('rules/no-commonjs'), { valid: [