From 6ec8b0796dfe43f586f63428e3ff8d79c172bee0 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 7 Nov 2021 15:01:40 -0800 Subject: [PATCH 1/6] meta: improve commit types --- package.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/package.json b/package.json index 3376656..e38b1bf 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,24 @@ "commit-msg": "validate-commit-msg", "pre-commit": "opt --in pre-commit --exec \"npm run validate\"" }, + "validate-commit-msg": { + "types": [ + "feat", + "fix", + "improvement", + "docs", + "style", + "refactor", + "perf", + "test", + "build", + "ci", + "breaking", + "revert", + "deps", + "meta" + ] + }, "commitizen": { "path": "./node_modules/cz-conventional-changelog" } From 617afcc2ac049531437dd2ebe3d16b6e8804c009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sun, 29 Aug 2021 20:20:25 +0200 Subject: [PATCH 2/6] breaking: support ESLint 8.x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michaël De Boey Co-authored-by: Jordan Harband Co-authored-by: 华 chore: simplify process.exit mock --- .github/workflows/node.yml | 12 ++ package.json | 7 +- src/bin/diff.js | 18 ++- src/bin/find.js | 9 +- src/lib/rule-finder.js | 68 +++++++---- test/bin/diff.js | 15 ++- test/bin/find.js | 93 ++++++++------- test/lib/rule-finder.js | 239 +++++++++++++++++-------------------- 8 files changed, 253 insertions(+), 208 deletions(-) diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index 9e9c43d..3269197 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -25,6 +25,7 @@ jobs: matrix: node-version: ${{ fromJson(needs.matrix.outputs.majors) }} eslint: + - 8 - 7 - 6 - 5 @@ -52,6 +53,15 @@ jobs: eslint: 4 - node-version: 4 eslint: 3 + exclude: + - node-version: 15 + eslint: 8 + - node-version: 13 + eslint: 8 + - node-version: 11 + eslint: 8 + - node-version: 10 + eslint: 8 steps: - uses: actions/checkout@v2 @@ -67,6 +77,8 @@ jobs: if: ${{ !matrix.ajv && matrix.eslint == 4 }} - run: npm install --no-save "ajv@6" if: ${{ !matrix.ajv && matrix.eslint == 5 }} + - run: npm install --no-save @eslint/eslintrc@0 + if: ${{ matrix.eslint != 8 }} - run: npm prune > /dev/null - run: npm ls > /dev/null - run: npm run cover diff --git a/package.json b/package.json index e38b1bf..875884f 100644 --- a/package.json +++ b/package.json @@ -48,9 +48,10 @@ "babel-preset-env": "^1.7.0", "codecov": "^2.3.1", "commitizen": "^2.10.1", + "create-require": "^1.1.1", "cz-conventional-changelog": "^2.1.0", - "eslint": "^3.12.0 || ^4 || ^5 || ^6 || ^7", - "eslint-plugin-json": "^2.1.2", + "eslint": "^3.12.0 || ^4 || ^5 || ^6 || ^7 || ^8", + "eslint-plugin-json": "^3.1.0", "ghooks": "^2.0.4", "in-publish": "^2.0.1", "mocha": "^3.5.3", @@ -64,7 +65,7 @@ "validate-commit-msg": "^2.14.0" }, "peerDependencies": { - "eslint": "^3.12.0 || ^4 || ^5 || ^6 || ^7" + "eslint": "^3.12.0 || ^4 || ^5 || ^6 || ^7 || ^8" }, "nyc": { "exclude": [ diff --git a/src/bin/diff.js b/src/bin/diff.js index ccf5002..5bdf493 100755 --- a/src/bin/diff.js +++ b/src/bin/diff.js @@ -17,8 +17,10 @@ const getSortedRules = require('../lib/sort-rules'); const flattenRulesDiff = require('../lib/flatten-rules-diff'); const stringifyRuleConfig = require('../lib/stringify-rule-config'); +(async function () { + const files = [argv._[0], argv._[1]]; -const collectedRules = getFilesToCompare(files).map(compareConfigs); +const collectedRules = await Promise.all(getFilesToCompare(files).map(compareConfigs)); const rulesCount = collectedRules.reduce( (prev, curr) => { @@ -66,13 +68,14 @@ function getFilesToCompare(allFiles) { return filesToCompare; } -function compareConfigs(currentFiles) { +async function compareConfigs(currentFiles) { + const ruleFinders = await Promise.all(currentFiles.slice(0, 2).map(getRuleFinder)); return { config1: path.basename(currentFiles[0]), config2: path.basename(currentFiles[1]), rules: rulesDifference( - getRuleFinder(currentFiles[0]), - getRuleFinder(currentFiles[1]) + ruleFinders[0], + ruleFinders[1] ) }; } @@ -94,3 +97,10 @@ function rulesDifference(a, b) { ) ); } + +process.exit(0); + +})().catch(/* istanbul ignore next */(e) => { + console.error(e); + process.exit(1); +}); diff --git a/src/bin/find.js b/src/bin/find.js index 8d0bd85..c3d8b0e 100755 --- a/src/bin/find.js +++ b/src/bin/find.js @@ -33,13 +33,15 @@ const getRuleURI = require('eslint-rule-documentation'); const getRuleFinder = require('../lib/rule-finder'); const cli = require('../lib/cli-util'); +(async function () { + const specifiedFile = argv._[0]; const finderOptions = { omitCore: !argv.core, includeDeprecated: argv.include === 'deprecated', ext: argv.ext }; -const ruleFinder = getRuleFinder(specifiedFile, finderOptions); +const ruleFinder = await getRuleFinder(specifiedFile, finderOptions); const errorOut = argv.error && !argv.n; let processExitCode = 0; @@ -76,3 +78,8 @@ if (!argv.c && !argv.p && !argv.a && !argv.u && !argv.d) { cli.write(); } process.exit(processExitCode); + +})().catch(/* istanbul ignore next */(e) => { + console.error(e); + process.exit(1); +}); diff --git a/src/lib/rule-finder.js b/src/lib/rule-finder.js index 26f2229..a85a4ca 100644 --- a/src/lib/rule-finder.js +++ b/src/lib/rule-finder.js @@ -18,20 +18,38 @@ function _getConfigFile(specifiedFile) { return require(path.join(process.cwd(), 'package.json')).main; } -function _getConfigs(configFile, files) { - const cliEngine = new eslint.CLIEngine({ - // Ignore any config applicable depending on the location on the filesystem - useEslintrc: false, - // Point to the particular config - configFile - }); - return new Set(files - .map(filePath => cliEngine.isPathIgnored(filePath) ? false : cliEngine.getConfigForFile(filePath)) - .filter(Boolean)); +async function _getConfigs(configFile, files) { + let isPathIgnored; + let getConfigForFile; + + if (eslint.ESLint) { + const esLint = new eslint.ESLint({ + // Ignore any config applicable depending on the location on the filesystem + useEslintrc: false, + // Point to the particular config + overrideConfigFile: configFile + }); + isPathIgnored = esLint.isPathIgnored.bind(esLint); + getConfigForFile = esLint.calculateConfigForFile.bind(esLint); + } else { + const cliEngine = new eslint.CLIEngine({ + // Ignore any config applicable depending on the location on the filesystem + useEslintrc: false, + // Point to the particular config + configFile + }); + isPathIgnored = cliEngine.isPathIgnored.bind(cliEngine); + getConfigForFile = cliEngine.getConfigForFile.bind(cliEngine); + } + + const configs = files.map(async filePath => ( + await isPathIgnored(filePath) ? false : getConfigForFile(filePath) + )); + return new Set((await Promise.all(configs)).filter(Boolean)); } -function _getConfig(configFile, files) { - return Array.from(_getConfigs(configFile, files)).reduce((prev, item) => { +async function _getConfig(configFile, files) { + return Array.from(await _getConfigs(configFile, files)).reduce((prev, item) => { return Object.assign(prev, item, {rules: Object.assign({}, prev.rules, item.rules)}); }, {}); } @@ -67,7 +85,7 @@ function _getPluginRules(config) { } function _getCoreRules() { - return eslint.linter.getRules(); + return (eslint.Linter ? new eslint.Linter() : eslint.linter).getRules(); } function _filterRuleNames(ruleNames, rules, predicate) { @@ -90,14 +108,7 @@ function _createExtensionRegExp(extensions) { return new RegExp(`.\\.(?:${normalizedExts.join("|")})$`); } -function RuleFinder(specifiedFile, {omitCore, includeDeprecated, ext = ['.js']}) { - const configFile = _getConfigFile(specifiedFile); - - const extensionRegExp = _createExtensionRegExp(ext); - const files = glob.sync(`**/*`, {dot: true, matchBase: true}) - .filter(file => extensionRegExp.test(file)); - - const config = _getConfig(configFile, files); +function RuleFinder(config, {omitCore, includeDeprecated}) { let currentRuleNames = _getCurrentNamesRules(config); if (omitCore) { currentRuleNames = currentRuleNames.filter(_isNotCore); @@ -135,6 +146,19 @@ function RuleFinder(specifiedFile, {omitCore, includeDeprecated, ext = ['.js']}) this.getDeprecatedRules = () => getSortedRules(deprecatedRuleNames); } +async function createRuleFinder(specifiedFile, options) { + const configFile = _getConfigFile(specifiedFile); + + const {ext = ['.js']} = options; + const extensionRegExp = _createExtensionRegExp(ext); + const files = glob.sync(`**/*`, {dot: true, matchBase: true}) + .filter(file => extensionRegExp.test(file)); + + const config = await _getConfig(configFile, files); + + return new RuleFinder(config, options); +} + module.exports = function (specifiedFile, options = {}) { - return new RuleFinder(specifiedFile, options); + return createRuleFinder(specifiedFile, options); }; diff --git a/test/bin/diff.js b/test/bin/diff.js index 969428b..ad5d280 100644 --- a/test/bin/diff.js +++ b/test/bin/diff.js @@ -3,9 +3,10 @@ const proxyquire = require('proxyquire'); const sinon = require('sinon'); const consoleLog = console.log; // eslint-disable-line no-console +const processExit = process.exit; const stub = { - '../lib/rule-finder'() { + async '../lib/rule-finder'() { return { getCurrentRules() {}, // Noop getCurrentRulesDetailed() {} // Noop @@ -15,6 +16,8 @@ const stub = { '../lib/object-diff': sinon.stub().returns([{'test-rule': {config1: 'foo-config', config2: 'bar-config'}}]) }; +let exitStatus; + describe('diff', () => { beforeEach(() => { process.argv = process.argv.slice(0, 2); @@ -24,18 +27,23 @@ describe('diff', () => { consoleLog(...args); } }); + exitStatus = new Promise(resolve => { + process.exit = resolve; + }); }); afterEach(() => { console.log.restore(); // eslint-disable-line no-console + process.exit = processExit; // purge yargs cache delete require.cache[require.resolve('yargs')]; }); - it('logs diff', () => { + it('logs diff', async () => { process.argv[2] = './foo'; process.argv[3] = './bar'; proxyquire('../../src/bin/diff', stub); + assert.strictEqual(await exitStatus, 0); assert.ok( console.log.calledWith( // eslint-disable-line no-console sinon.match( @@ -45,11 +53,12 @@ describe('diff', () => { ); }); - it('logs diff verbosely', () => { + it('logs diff verbosely', async () => { process.argv[2] = '--verbose'; process.argv[3] = './foo'; process.argv[4] = './bar'; proxyquire('../../src/bin/diff', stub); + assert.strictEqual(await exitStatus, 0); assert.ok( console.log.calledWith( // eslint-disable-line no-console sinon.match( diff --git a/test/bin/find.js b/test/bin/find.js index b546d81..adb8c25 100644 --- a/test/bin/find.js +++ b/test/bin/find.js @@ -17,7 +17,7 @@ let exitStatus; describe('bin', () => { beforeEach(() => { stub = { - '../lib/rule-finder'() { + async '../lib/rule-finder'() { return { getCurrentRules, getPluginRules, @@ -34,10 +34,9 @@ describe('bin', () => { } consoleLog(...args); }; - exitStatus = null; - process.exit = status => { - exitStatus = status; - }; + exitStatus = new Promise(resolve => { + process.exit = resolve; + }); process.argv = process.argv.slice(0, 2); }); @@ -48,7 +47,7 @@ describe('bin', () => { delete require.cache[require.resolve('yargs')]; }); - it('no option', () => { + it('no option', async () => { let callCount = 0; console.log = (...args) => { // eslint-disable-line no-console callCount += 1; @@ -60,122 +59,125 @@ describe('bin', () => { consoleLog(...args); }; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); assert.equal(callCount, 3); // eslint-disable-line no-console }); - it('option -c|--current', () => { + it('option -c|--current', async () => { process.argv[2] = '-c'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); assert.ok(getCurrentRules.called); - assert.equal(exitStatus, 0); }); - it('option -p|--plugin', () => { + it('option -p|--plugin', async () => { process.argv[2] = '-p'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); assert.ok(getPluginRules.called); - assert.equal(exitStatus, 0); }); - it('option -a|--all-available', () => { + it('option -a|--all-available', async () => { process.argv[2] = '-a'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); assert.ok(getAllAvailableRules.called); process.argv[2] = '--all-available'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); assert.ok(getAllAvailableRules.called); - assert.equal(exitStatus, 0); }); - it('option -a along with --ext', () => { + it('option -a along with --ext', async () => { process.argv[2] = '-a'; process.argv[3] = '--ext .json'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); assert.ok(getAllAvailableRules.called); - assert.equal(exitStatus, 0); }); - it('option -a along with multi --ext', () => { + it('option -a along with multi --ext', async () => { process.argv[2] = '-a'; process.argv[3] = '--ext .js'; process.argv[4] = '--ext .json'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); assert.ok(getAllAvailableRules.called); - assert.equal(exitStatus, 0); }); - it('option -u|--unused', () => { + it('option -u|--unused', async () => { process.argv[2] = '-u'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 1); assert.ok(getUnusedRules.called); - assert.equal(exitStatus, 1); }); - it('options -u|--unused and no unused rules found', () => { + it('options -u|--unused and no unused rules found', async () => { getUnusedRules.returns([]); process.argv[2] = '-u'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); assert.ok(getUnusedRules.called); - assert.equal(exitStatus, 0); }); - it('option -u|--unused along with -n', () => { + it('option -u|--unused along with -n', async () => { process.argv[2] = '-u'; process.argv[3] = '-n'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); assert.ok(getUnusedRules.called); - assert.equal(exitStatus, 0); }); - it('option -u|--unused along with --no-error', () => { + it('option -u|--unused along with --no-error', async () => { process.argv[2] = '-u'; process.argv[3] = '--no-error'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); assert.ok(getUnusedRules.called); - assert.equal(exitStatus, 0); }); - it('option -d|--deprecated', () => { + it('option -d|--deprecated', async () => { process.argv[2] = '-d'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 1); assert.ok(getDeprecatedRules.called); - assert.equal(exitStatus, 1); }); - it('options -d|--deprecated and no deprecated rules found', () => { + it('options -d|--deprecated and no deprecated rules found', async () => { getDeprecatedRules.returns([]); process.argv[2] = '-d'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); assert.ok(getDeprecatedRules.called); - assert.equal(exitStatus, 0); }); - it('option -d|--deprecated along with -n', () => { + it('option -d|--deprecated along with -n', async () => { process.argv[2] = '-d'; process.argv[3] = '-n'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); assert.ok(getDeprecatedRules.called); - assert.equal(exitStatus, 0); }); - it('option -d|--deprecated along with --no-error', () => { + it('option -d|--deprecated along with --no-error', async () => { process.argv[2] = '-d'; process.argv[3] = '--no-error'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); assert.ok(getDeprecatedRules.called); - assert.equal(exitStatus, 0); }); - it('logs verbosely', () => { + it('logs verbosely', async () => { process.argv[2] = '-c'; process.argv[3] = '-v'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); assert.ok(getCurrentRules.called); }); - it('logs core rules', () => { + it('logs core rules', async () => { stub = { - '../lib/rule-finder'(specifiedFile, options) { + async '../lib/rule-finder'(specifiedFile, options) { return { getCurrentRules() { assert(!options.omitCore); @@ -186,11 +188,12 @@ describe('bin', () => { }; process.argv[2] = '-c'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); }); - it('does not log core rules with --no-core', () => { + it('does not log core rules with --no-core', async () => { stub = { - '../lib/rule-finder'(specifiedFile, options) { + async '../lib/rule-finder'(specifiedFile, options) { return { getCurrentRules() { assert(options.omitCore); @@ -202,11 +205,12 @@ describe('bin', () => { process.argv[2] = '-c'; process.argv[3] = '--no-core'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); }); - it('does not include deprecated rules by default', () => { + it('does not include deprecated rules by default', async () => { stub = { - '../lib/rule-finder'(specifiedFile, options) { + async '../lib/rule-finder'(specifiedFile, options) { return { getAllAvailableRules() { assert(!options.includeDeprecated); @@ -217,11 +221,12 @@ describe('bin', () => { }; process.argv[2] = '-a'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); }); - it('includes deprecated rules with --include deprecated', () => { + it('includes deprecated rules with --include deprecated', async () => { stub = { - '../lib/rule-finder'(specifiedFile, options) { + async '../lib/rule-finder'(specifiedFile, options) { return { getAllAvailableRules() { assert(options.includeDeprecated); @@ -233,11 +238,12 @@ describe('bin', () => { process.argv[2] = '-a'; process.argv[3] = '--include=deprecated'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); }); - it('includes deprecated rules with -i deprecated', () => { + it('includes deprecated rules with -i deprecated', async () => { stub = { - '../lib/rule-finder'(specifiedFile, options) { + async '../lib/rule-finder'(specifiedFile, options) { return { getAllAvailableRules() { assert(options.includeDeprecated); @@ -250,5 +256,6 @@ describe('bin', () => { process.argv[3] = '-i'; process.argv[4] = 'deprecated'; proxyquire('../../src/bin/find', stub); + assert.strictEqual(await exitStatus, 0); }); }); diff --git a/test/lib/rule-finder.js b/test/lib/rule-finder.js index 453dda9..d9802dd 100644 --- a/test/lib/rule-finder.js +++ b/test/lib/rule-finder.js @@ -1,65 +1,38 @@ const path = require('path'); +const createRequire = require('create-require'); const assert = require('assert'); const proxyquire = require('proxyquire'); const semver = require('semver'); const eslintPkg = require('eslint/package.json'); -let ModuleResolver; -try { - if (semver.satisfies(eslintPkg.version, '>= 7.12')) { - // eslint 7.12+ - ModuleResolver = require('@eslint/eslintrc/lib/shared/relative-module-resolver'); - } else { - throw { code: 'MODULE_NOT_FOUND' }; - } -} catch (err) { - if (err.code !== 'MODULE_NOT_FOUND') { - throw err; - } - try { - // eslint v6 - v7.11: load the actual module - ModuleResolver = require('eslint/lib/shared/relative-module-resolver'); - } catch (err) { - if (err.code !== 'MODULE_NOT_FOUND') { - throw err; - } - // eslint < 6: ModuleResolver is `undefined`, which is okay. The proxyquire - // override for ../shared/relative-module-resolver won't be used because - // eslint < 6 does not have that module and so does not try to load it. - ModuleResolver = undefined; - } -} - const processCwd = process.cwd; const eslintVersion = semver.satisfies(eslintPkg.version, '< 5') ? 'prior-v5' : 'post-v5'; const supportsScopedPlugins = semver.satisfies(eslintPkg.version, '>= 5'); -const moduleResolver = { - resolve(name, relative) { +const mockCreateRequire = (getExport, plugins, relative) => { + // Use the mocked require. + const moduleRequire = (id) => { + const targetExport = getExport(); + return module.children + .find((m) => m.exports === targetExport) + .require(id); + }; + return Object.assign(moduleRequire, { // The strategy is simple: if called with one of our plugins, just return // the module name, as-is. This is a lie because what we return is not a // path, but it is simple, and works. Otherwise, we just call the original // `resolve` from the stock module. - return [ - 'eslint-plugin-plugin', - 'eslint-plugin-no-rules', - '@scope/eslint-plugin-scoped-plugin', - '@scope/eslint-plugin', - '@scope-with-dash/eslint-plugin-scoped-with-dash-plugin', - '@scope-with-dash/eslint-plugin' - ].includes(name) ? - name : - ModuleResolver.resolve(name, relative); - }, - '@global': true, - '@noCallThru': true + resolve: (name) => ( + plugins.includes(name) ? name : createRequire(relative).resolve(name) + ) + }); }; const getRuleFinder = proxyquire('../../src/lib/rule-finder', { eslint: { - linter: { + Linter: class { getRules() { return new Map() .set('foo-rule', {}) @@ -69,17 +42,21 @@ const getRuleFinder = proxyquire('../../src/lib/rule-finder', { } } }, - // - // This following module override is needed for eslint v6 and over. The module - // path that we pass here is literally the one used in eslint (specifically in - // eslint/lib/cli-engine/config-array-factory.js) - // - // The stock `resolve` method attempts to resolve to a file path the module - // name passed in `name` relative to the path in `relative`. We have to - // override that function, otherwise eslint fails to "load" our plugins. - // - '../shared/relative-module-resolver': moduleResolver, // in eslint < 7.12, from eslint/lib/cli-engine/config-array-factory.js - './shared/relative-module-resolver': moduleResolver, // in eslint 7.12+, from @eslint/eslintrc/lib/config-array-factory.js + module: { + createRequire: (relative) => mockCreateRequire( + () => getRuleFinder, + [ + 'eslint-plugin-plugin', + 'eslint-plugin-no-rules', + '@scope/eslint-plugin-scoped-plugin', + '@scope/eslint-plugin', + '@scope-with-dash/eslint-plugin-scoped-with-dash-plugin', + '@scope-with-dash/eslint-plugin' + ], + relative + ), + '@global': true + }, 'eslint-plugin-plugin': { rules: { 'foo-rule': {}, @@ -150,18 +127,9 @@ function assertDeepEqual(a, b) { return assert.deepEqual(a, bWithoutScoped); } -const dedupeModuleResolver = { - resolve(name, relative) { - return name === 'eslint-plugin-plugin' ? - name : - ModuleResolver.resolve(name, relative); - }, - '@global': true, - '@noCallThru': true -}; const getRuleFinderForDedupeTests = proxyquire('../../src/lib/rule-finder', { eslint: { - linter: { + Linter: class { getRules() { return new Map() .set('foo-rule', {}) @@ -171,9 +139,16 @@ const getRuleFinderForDedupeTests = proxyquire('../../src/lib/rule-finder', { } } }, - // See the long comment in `getRuleFinder` above to learn what the point of this override is. - '../shared/relative-module-resolver': dedupeModuleResolver, // in eslint < 7.12, from eslint/lib/cli-engine/config-array-factory.js - './shared/relative-module-resolver': dedupeModuleResolver, // in eslint 7.12+, from @eslint/eslintrc/lib/config-array-factory.js + module: { + createRequire: (relative) => mockCreateRequire( + () => getRuleFinderForDedupeTests, + [ + 'eslint-plugin-plugin' + ], + relative + ), + '@global': true + }, 'eslint-plugin-plugin': { rules: { 'duplicate-foo-rule': {}, @@ -199,72 +174,72 @@ describe('rule-finder', function() { process.cwd = processCwd; }); - it('no specifiedFile - unused rules', () => { + it('no specifiedFile - unused rules', async () => { process.cwd = function () { return noSpecifiedFile; }; - const ruleFinder = getRuleFinder(); + const ruleFinder = await getRuleFinder(); assertDeepEqual(ruleFinder.getUnusedRules(), ['bar-rule', 'baz-rule']); }); - it('no specifiedFile - unused rules including deprecated', () => { + it('no specifiedFile - unused rules including deprecated', async () => { process.cwd = function () { return noSpecifiedFile; }; - const ruleFinder = getRuleFinder(null, {includeDeprecated: true}); + const ruleFinder = await getRuleFinder(null, {includeDeprecated: true}); assertDeepEqual(ruleFinder.getUnusedRules(), ['bar-rule', 'baz-rule', 'old-rule']); }); - it('no specifiedFile - current rules', () => { + it('no specifiedFile - current rules', async () => { process.cwd = function () { return noSpecifiedFile; }; - const ruleFinder = getRuleFinder(); + const ruleFinder = await getRuleFinder(); assertDeepEqual(ruleFinder.getCurrentRules(), ['foo-rule']); }); - it('no specifiedFile - current rule config', () => { + it('no specifiedFile - current rule config', async () => { process.cwd = function () { return noSpecifiedFile; }; - const ruleFinder = getRuleFinder(); + const ruleFinder = await getRuleFinder(); assertDeepEqual(ruleFinder.getCurrentRulesDetailed(), {'foo-rule': [2]}); }); - it('no specifiedFile - plugin rules', () => { + it('no specifiedFile - plugin rules', async () => { process.cwd = function () { return noSpecifiedFile; }; - const ruleFinder = getRuleFinder(); + const ruleFinder = await getRuleFinder(); assertDeepEqual(ruleFinder.getPluginRules(), []); }); - it('no specifiedFile - all available rules', () => { + it('no specifiedFile - all available rules', async () => { process.cwd = function () { return noSpecifiedFile; }; - const ruleFinder = getRuleFinder(); + const ruleFinder = await getRuleFinder(); assertDeepEqual(ruleFinder.getAllAvailableRules(), ['bar-rule', 'baz-rule', 'foo-rule']); }); - it('no specifiedFile - all available rules without core', () => { + it('no specifiedFile - all available rules without core', async () => { process.cwd = function () { return noSpecifiedFile; }; - const ruleFinder = getRuleFinder(null, {omitCore: true}); + const ruleFinder = await getRuleFinder(null, {omitCore: true}); assertDeepEqual(ruleFinder.getAllAvailableRules(), []); }); - it('no specifiedFile - all available rules including deprecated', () => { + it('no specifiedFile - all available rules including deprecated', async () => { process.cwd = function () { return noSpecifiedFile; }; - const ruleFinder = getRuleFinder(null, {includeDeprecated: true}); + const ruleFinder = await getRuleFinder(null, {includeDeprecated: true}); assertDeepEqual(ruleFinder.getAllAvailableRules(), ['bar-rule', 'baz-rule', 'foo-rule', 'old-rule']); }); - it('specifiedFile (relative path) - unused rules', () => { - const ruleFinder = getRuleFinder(specifiedFileRelative); + it('specifiedFile (relative path) - unused rules', async () => { + const ruleFinder = await getRuleFinder(specifiedFileRelative); assertDeepEqual(ruleFinder.getUnusedRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/scoped-with-dash-plugin/bar-rule', @@ -277,8 +252,8 @@ describe('rule-finder', function() { ]); }); - it('specifiedFile (relative path) - unused rules including deprecated', () => { - const ruleFinder = getRuleFinder(specifiedFileRelative, {includeDeprecated: true}); + it('specifiedFile (relative path) - unused rules including deprecated', async () => { + const ruleFinder = await getRuleFinder(specifiedFileRelative, {includeDeprecated: true}); assertDeepEqual(ruleFinder.getUnusedRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/old-plugin-rule', @@ -297,8 +272,8 @@ describe('rule-finder', function() { ]); }); - it('specifiedFile (relative path) - current rules', () => { - const ruleFinder = getRuleFinder(specifiedFileRelative); + it('specifiedFile (relative path) - current rules', async () => { + const ruleFinder = await getRuleFinder(specifiedFileRelative); assertDeepEqual(ruleFinder.getCurrentRules(), [ '@scope-with-dash/foo-rule', '@scope-with-dash/scoped-with-dash-plugin/foo-rule', @@ -309,8 +284,8 @@ describe('rule-finder', function() { ]); }); - it('specifiedFile (relative path) - current rules with ext', () => { - const ruleFinder = getRuleFinder(specifiedFileRelative, { ext: ['.json'] }); + it('specifiedFile (relative path) - current rules with ext', async () => { + const ruleFinder = await getRuleFinder(specifiedFileRelative, { ext: ['.json'] }); assertDeepEqual(ruleFinder.getCurrentRules(), [ '@scope-with-dash/foo-rule', '@scope-with-dash/scoped-with-dash-plugin/foo-rule', @@ -321,8 +296,8 @@ describe('rule-finder', function() { ]); }); - it('specifiedFile (relative path) - current rules with ext without dot', () => { - const ruleFinder = getRuleFinder(specifiedFileRelative, { ext: ['json'] }); + it('specifiedFile (relative path) - current rules with ext without dot', async () => { + const ruleFinder = await getRuleFinder(specifiedFileRelative, { ext: ['json'] }); assertDeepEqual(ruleFinder.getCurrentRules(), [ '@scope-with-dash/foo-rule', '@scope-with-dash/scoped-with-dash-plugin/foo-rule', @@ -333,13 +308,13 @@ describe('rule-finder', function() { ]); }); - it('specifiedFile (relative path) - current rules with ext not found', () => { - const ruleFinder = getRuleFinder(specifiedFileRelative, { ext: ['.ts'] }); + it('specifiedFile (relative path) - current rules with ext not found', async () => { + const ruleFinder = await getRuleFinder(specifiedFileRelative, { ext: ['.ts'] }); assertDeepEqual(ruleFinder.getCurrentRules(), []); }); - it('specifiedFile (relative path) - current rule config', () => { - const ruleFinder = getRuleFinder(specifiedFileRelative); + it('specifiedFile (relative path) - current rule config', async () => { + const ruleFinder = await getRuleFinder(specifiedFileRelative); assertDeepEqual(ruleFinder.getCurrentRulesDetailed(), { '@scope-with-dash/foo-rule': [2], '@scope-with-dash/scoped-with-dash-plugin/foo-rule': [2], @@ -350,8 +325,8 @@ describe('rule-finder', function() { }); }); - it('specifiedFile (relative path) - plugin rules', () => { - const ruleFinder = getRuleFinder(specifiedFileRelative); + it('specifiedFile (relative path) - plugin rules', async () => { + const ruleFinder = await getRuleFinder(specifiedFileRelative); assertDeepEqual(ruleFinder.getPluginRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/foo-rule', @@ -367,8 +342,8 @@ describe('rule-finder', function() { ]); }); - it('specifiedFile (relative path) - plugin rules including deprecated', () => { - const ruleFinder = getRuleFinder(specifiedFileRelative, {includeDeprecated: true}); + it('specifiedFile (relative path) - plugin rules including deprecated', async () => { + const ruleFinder = await getRuleFinder(specifiedFileRelative, {includeDeprecated: true}); assertDeepEqual(ruleFinder.getPluginRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/foo-rule', @@ -389,8 +364,8 @@ describe('rule-finder', function() { ]); }); - it('specifiedFile (relative path) - all available rules', () => { - const ruleFinder = getRuleFinder(specifiedFileRelative); + it('specifiedFile (relative path) - all available rules', async () => { + const ruleFinder = await getRuleFinder(specifiedFileRelative); assertDeepEqual( ruleFinder.getAllAvailableRules(), [ @@ -412,8 +387,8 @@ describe('rule-finder', function() { ); }); - it('specifiedFile (relative path) - all available rules without core', () => { - const ruleFinder = getRuleFinder(specifiedFileRelative, {omitCore: true}); + it('specifiedFile (relative path) - all available rules without core', async () => { + const ruleFinder = await getRuleFinder(specifiedFileRelative, {omitCore: true}); assertDeepEqual( ruleFinder.getAllAvailableRules(), [ @@ -432,8 +407,8 @@ describe('rule-finder', function() { ); }); - it('specifiedFile (relative path) - all available rules including deprecated', () => { - const ruleFinder = getRuleFinder(specifiedFileRelative, {includeDeprecated: true}); + it('specifiedFile (relative path) - all available rules including deprecated', async () => { + const ruleFinder = await getRuleFinder(specifiedFileRelative, {includeDeprecated: true}); assertDeepEqual( ruleFinder.getAllAvailableRules(), [ @@ -461,8 +436,8 @@ describe('rule-finder', function() { ); }); - it('specifiedFile (absolute path) - unused rules', () => { - const ruleFinder = getRuleFinder(specifiedFileAbsolute); + it('specifiedFile (absolute path) - unused rules', async () => { + const ruleFinder = await getRuleFinder(specifiedFileAbsolute); assertDeepEqual(ruleFinder.getUnusedRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/scoped-with-dash-plugin/bar-rule', @@ -475,8 +450,8 @@ describe('rule-finder', function() { ]); }); - it('specifiedFile (absolute path) - unused rules', () => { - const ruleFinder = getRuleFinder(specifiedFileAbsolute, {includeDeprecated: true}); + it('specifiedFile (absolute path) - unused rules', async () => { + const ruleFinder = await getRuleFinder(specifiedFileAbsolute, {includeDeprecated: true}); assertDeepEqual(ruleFinder.getUnusedRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/old-plugin-rule', @@ -495,8 +470,8 @@ describe('rule-finder', function() { ]); }); - it('specifiedFile (absolute path) - current rules', () => { - const ruleFinder = getRuleFinder(specifiedFileAbsolute); + it('specifiedFile (absolute path) - current rules', async () => { + const ruleFinder = await getRuleFinder(specifiedFileAbsolute); assertDeepEqual(ruleFinder.getCurrentRules(), [ '@scope-with-dash/foo-rule', '@scope-with-dash/scoped-with-dash-plugin/foo-rule', @@ -507,8 +482,8 @@ describe('rule-finder', function() { ]); }); - it('specifiedFile (absolute path) - current rule config', () => { - const ruleFinder = getRuleFinder(specifiedFileAbsolute); + it('specifiedFile (absolute path) - current rule config', async () => { + const ruleFinder = await getRuleFinder(specifiedFileAbsolute); assertDeepEqual(ruleFinder.getCurrentRulesDetailed(), { '@scope-with-dash/foo-rule': [2], '@scope-with-dash/scoped-with-dash-plugin/foo-rule': [2], @@ -519,8 +494,8 @@ describe('rule-finder', function() { }); }); - it('specifiedFile (absolute path) - plugin rules', () => { - const ruleFinder = getRuleFinder(specifiedFileAbsolute); + it('specifiedFile (absolute path) - plugin rules', async () => { + const ruleFinder = await getRuleFinder(specifiedFileAbsolute); assertDeepEqual(ruleFinder.getPluginRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/foo-rule', @@ -536,8 +511,8 @@ describe('rule-finder', function() { ]); }); - it('specifiedFile (absolute path) - plugin rules including deprecated', () => { - const ruleFinder = getRuleFinder(specifiedFileAbsolute, {includeDeprecated: true}); + it('specifiedFile (absolute path) - plugin rules including deprecated', async () => { + const ruleFinder = await getRuleFinder(specifiedFileAbsolute, {includeDeprecated: true}); assertDeepEqual(ruleFinder.getPluginRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/foo-rule', @@ -558,8 +533,8 @@ describe('rule-finder', function() { ]); }); - it('specifiedFile (absolute path) - all available rules', () => { - const ruleFinder = getRuleFinder(specifiedFileAbsolute); + it('specifiedFile (absolute path) - all available rules', async () => { + const ruleFinder = await getRuleFinder(specifiedFileAbsolute); assertDeepEqual( ruleFinder.getAllAvailableRules(), [ @@ -581,8 +556,8 @@ describe('rule-finder', function() { ); }); - it('specifiedFile (absolute path) - all available rules including deprecated', () => { - const ruleFinder = getRuleFinder(specifiedFileAbsolute, {includeDeprecated: true}); + it('specifiedFile (absolute path) - all available rules including deprecated', async () => { + const ruleFinder = await getRuleFinder(specifiedFileAbsolute, {includeDeprecated: true}); assertDeepEqual( ruleFinder.getAllAvailableRules(), [ @@ -610,8 +585,8 @@ describe('rule-finder', function() { ); }); - it('specifiedFile (absolute path) without rules - plugin rules', () => { - const ruleFinder = getRuleFinder(noRulesFile); + it('specifiedFile (absolute path) without rules - plugin rules', async () => { + const ruleFinder = await getRuleFinder(noRulesFile); assertDeepEqual(ruleFinder.getPluginRules(), [ 'plugin/bar-rule', 'plugin/baz-rule', @@ -619,8 +594,8 @@ describe('rule-finder', function() { ]); }); - it('dedupes plugin rules - all available rules', () => { - const ruleFinder = getRuleFinderForDedupeTests(noDuplicateRulesFiles); + it('dedupes plugin rules - all available rules', async () => { + const ruleFinder = await getRuleFinderForDedupeTests(noDuplicateRulesFiles); assertDeepEqual(ruleFinder.getAllAvailableRules(), [ 'bar-rule', 'foo-rule', @@ -629,21 +604,21 @@ describe('rule-finder', function() { ]); }); - it('dedupes plugin rules - unused rules', () => { - const ruleFinder = getRuleFinderForDedupeTests(noDuplicateRulesFiles); + it('dedupes plugin rules - unused rules', async () => { + const ruleFinder = await getRuleFinderForDedupeTests(noDuplicateRulesFiles); assertDeepEqual(ruleFinder.getUnusedRules(), [ 'bar-rule', 'plugin/duplicate-foo-rule' ]); }); - it('specifiedFile (absolute path) without deprecated rules - deprecated rules', () => { - const ruleFinder = getRuleFinder(specifiedFileAbsolute); + it('specifiedFile (absolute path) without deprecated rules - deprecated rules', async () => { + const ruleFinder = await getRuleFinder(specifiedFileAbsolute); assertDeepEqual(ruleFinder.getDeprecatedRules(), []); }); - it('specifiedFile (absolute path) with deprecated rules - deprecated rules', () => { - const ruleFinder = getRuleFinder(usingDeprecatedRulesFile); + it('specifiedFile (absolute path) with deprecated rules - deprecated rules', async () => { + const ruleFinder = await getRuleFinder(usingDeprecatedRulesFile); assertDeepEqual(ruleFinder.getDeprecatedRules(), [ '@scope-with-dash/old-plugin-rule', '@scope-with-dash/scoped-with-dash-plugin/old-plugin-rule', From 7fec8118cfad55138c9f3d0740099fda57bda3a1 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 7 Nov 2021 15:20:13 -0800 Subject: [PATCH 3/6] breaking: drop eslint < 7 --- .eslintrc | 5 +- .github/workflows/node.yml | 29 ------- package.json | 7 +- src/lib/normalize-plugin-name.js | 67 +-------------- .../prior-v5/eslint-dedupe-plugin-rules.json | 9 -- .../eslint-with-deprecated-rules.json | 11 --- .../eslint-with-plugin-with-no-rules.json | 7 -- test/fixtures/prior-v5/eslint.json | 8 -- test/fixtures/prior-v5/eslint.yml | 5 -- test/fixtures/prior-v5/eslintrc | 5 -- test/fixtures/prior-v5/no-path/index.js | 5 -- test/fixtures/prior-v5/no-path/package.json | 7 -- test/lib/rule-finder.js | 84 ++++++++----------- 13 files changed, 38 insertions(+), 211 deletions(-) delete mode 100644 test/fixtures/prior-v5/eslint-dedupe-plugin-rules.json delete mode 100644 test/fixtures/prior-v5/eslint-with-deprecated-rules.json delete mode 100644 test/fixtures/prior-v5/eslint-with-plugin-with-no-rules.json delete mode 100644 test/fixtures/prior-v5/eslint.json delete mode 100644 test/fixtures/prior-v5/eslint.yml delete mode 100644 test/fixtures/prior-v5/eslintrc delete mode 100644 test/fixtures/prior-v5/no-path/index.js delete mode 100644 test/fixtures/prior-v5/no-path/package.json diff --git a/.eslintrc b/.eslintrc index 4b64162..b80673d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,10 +5,7 @@ "node": true }, "parserOptions": { - "ecmaFeatures": { - "impliedStrict": true - }, - "ecmaVersion": 2017 + "ecmaVersion": 2018 }, "plugins": ["json"], "root": true diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index 3269197..c61b02b 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -27,32 +27,9 @@ jobs: eslint: - 8 - 7 - - 6 - - 5 - - 4 - - 3 include: - node-version: 14 eslint: 7.7 - - node-version: 8 - eslint: 6 - - node-version: 8 - eslint: 5 - - node-version: 8 - eslint: 4 - - node-version: 8 - eslint: 3 - - node-version: 6 - eslint: 5 - ajv: 5 - - node-version: 6 - eslint: 4 - - node-version: 6 - eslint: 3 - - node-version: 4 - eslint: 4 - - node-version: 4 - eslint: 3 exclude: - node-version: 15 eslint: 8 @@ -71,12 +48,6 @@ jobs: node-version: ${{ matrix.node-version }} skip-ls-check: true - run: npm install --no-save eslint@${{ matrix.eslint }} - - run: npm install --no-save "ajv@${{ matrix.ajv }}" - if: ${{ !!matrix.ajv }} - - run: npm install --no-save "ajv@5" - if: ${{ !matrix.ajv && matrix.eslint == 4 }} - - run: npm install --no-save "ajv@6" - if: ${{ !matrix.ajv && matrix.eslint == 5 }} - run: npm install --no-save @eslint/eslintrc@0 if: ${{ matrix.eslint != 8 }} - run: npm prune > /dev/null diff --git a/package.json b/package.json index 875884f..793e831 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "yargs": "^8.0.2" }, "devDependencies": { - "ajv": "^5 || ^6", "all-contributors-cli": "^4.11.2", "aud": "^1.1.5", "babel-cli": "^6.26.0", @@ -50,7 +49,7 @@ "commitizen": "^2.10.1", "create-require": "^1.1.1", "cz-conventional-changelog": "^2.1.0", - "eslint": "^3.12.0 || ^4 || ^5 || ^6 || ^7 || ^8", + "eslint": "^7 || ^8.2.0", "eslint-plugin-json": "^3.1.0", "ghooks": "^2.0.4", "in-publish": "^2.0.1", @@ -65,7 +64,7 @@ "validate-commit-msg": "^2.14.0" }, "peerDependencies": { - "eslint": "^3.12.0 || ^4 || ^5 || ^6 || ^7 || ^8" + "eslint": "^7 || ^8.2.0" }, "nyc": { "exclude": [ @@ -108,6 +107,6 @@ }, "homepage": "https://github.com/sarbbottam/eslint-find-rules#readme", "engines": { - "node": ">= 4" + "node": "^10.12.0 || >=12.0.0 || ^14.17.0 || >=16.0.0" } } diff --git a/src/lib/normalize-plugin-name.js b/src/lib/normalize-plugin-name.js index ce6746d..f342fb8 100644 --- a/src/lib/normalize-plugin-name.js +++ b/src/lib/normalize-plugin-name.js @@ -8,7 +8,7 @@ function _getNormalizer() { } const eslintVersionFunctions = [ - // eslint >= 7.0.0 + // eslint >= 7.8.0 function () { const ESLintExports = require('eslint'); @@ -36,71 +36,6 @@ function _getNormalizer() { getShorthandName: normalizer.getShorthandName }; }, - // eslint 6.0.0 - 6.0.1 - function () { - const normalizer = require('eslint/lib/cli-engine/naming'); - - return { - normalizePackageName: normalizer.normalizePackageName, - getShorthandName: normalizer.getShorthandName - }; - }, - // eslint 5 - function () { - const normalizer = require('eslint/lib/util/naming'); - - return { - normalizePackageName: normalizer.normalizePackageName, - getShorthandName: normalizer.getShorthandName - }; - }, - // eslint 4 - function () { - const normalizer = require('eslint/lib/util/naming'); - - return { - normalizePackageName: normalizer.normalizePackageName, - getShorthandName: normalizer.removeNamespaceFromTerm - }; - }, - // eslint 3 - function () { - const normalizer = require('eslint/lib/config/plugins'); - - const PLUGIN_NAME_PREFIX = 'eslint-plugin-'; - - function parsePluginName(pluginName) { - const pluginNamespace = normalizer.getNamespace(pluginName); - const pluginNameWithoutNamespace = normalizer.removeNamespace(pluginName); - const pluginNameWithoutPrefix = normalizer.removePrefix(pluginNameWithoutNamespace); - - return { - pluginNamespace, - pluginNameWithoutPrefix - }; - } - - function normalizePackageName(pluginName) { - const sections = parsePluginName(pluginName); - const longName = sections.pluginNamespace + - PLUGIN_NAME_PREFIX + - sections.pluginNameWithoutPrefix; - - return longName; - } - - function getShorthandName(pluginName) { - const sections = parsePluginName(pluginName); - const shortName = sections.pluginNamespace + sections.pluginNameWithoutPrefix; - - return shortName; - } - - return { - normalizePackageName, - getShorthandName - }; - } ]; for (const tryEslintVersion of eslintVersionFunctions) { diff --git a/test/fixtures/prior-v5/eslint-dedupe-plugin-rules.json b/test/fixtures/prior-v5/eslint-dedupe-plugin-rules.json deleted file mode 100644 index db07397..0000000 --- a/test/fixtures/prior-v5/eslint-dedupe-plugin-rules.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "./eslintrc", - "plugins": [ - "plugin" - ], - "rules": { - "plugin/duplicate-bar-rule": [2] - } -} diff --git a/test/fixtures/prior-v5/eslint-with-deprecated-rules.json b/test/fixtures/prior-v5/eslint-with-deprecated-rules.json deleted file mode 100644 index 93b52f0..0000000 --- a/test/fixtures/prior-v5/eslint-with-deprecated-rules.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "plugins": [ - "plugin" - ], - "rules": { - "foo-rule": [2], - "old-rule": [2], - "plugin/foo-rule": [2], - "plugin/old-plugin-rule": [2] - } -} diff --git a/test/fixtures/prior-v5/eslint-with-plugin-with-no-rules.json b/test/fixtures/prior-v5/eslint-with-plugin-with-no-rules.json deleted file mode 100644 index 09c13b3..0000000 --- a/test/fixtures/prior-v5/eslint-with-plugin-with-no-rules.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "plugins": [ - "plugin", - "no-rules" - ], - "rules": {} -} diff --git a/test/fixtures/prior-v5/eslint.json b/test/fixtures/prior-v5/eslint.json deleted file mode 100644 index ca9c623..0000000 --- a/test/fixtures/prior-v5/eslint.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "./eslint.yml", - "plugins": [ - "plugin" - ], - "rules": { - } -} diff --git a/test/fixtures/prior-v5/eslint.yml b/test/fixtures/prior-v5/eslint.yml deleted file mode 100644 index c39e9d5..0000000 --- a/test/fixtures/prior-v5/eslint.yml +++ /dev/null @@ -1,5 +0,0 @@ -extends: - ./eslintrc -rules: - bar-rule: - - 2 diff --git a/test/fixtures/prior-v5/eslintrc b/test/fixtures/prior-v5/eslintrc deleted file mode 100644 index 157df27..0000000 --- a/test/fixtures/prior-v5/eslintrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "rules": { - "foo-rule": [2] - } -} diff --git a/test/fixtures/prior-v5/no-path/index.js b/test/fixtures/prior-v5/no-path/index.js deleted file mode 100644 index e853bb4..0000000 --- a/test/fixtures/prior-v5/no-path/index.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - rules: { - 'foo-rule': [2] - } -} diff --git a/test/fixtures/prior-v5/no-path/package.json b/test/fixtures/prior-v5/no-path/package.json deleted file mode 100644 index 05749d7..0000000 --- a/test/fixtures/prior-v5/no-path/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "fake-project", - "version": "0.0.0", - "description": "Simulating a project's package.json.", - "private": true, - "main": "./index.js" -} diff --git a/test/lib/rule-finder.js b/test/lib/rule-finder.js index d9802dd..264ff3a 100644 --- a/test/lib/rule-finder.js +++ b/test/lib/rule-finder.js @@ -9,7 +9,6 @@ const eslintPkg = require('eslint/package.json'); const processCwd = process.cwd; const eslintVersion = semver.satisfies(eslintPkg.version, '< 5') ? 'prior-v5' : 'post-v5'; -const supportsScopedPlugins = semver.satisfies(eslintPkg.version, '>= 5'); const mockCreateRequire = (getExport, plugins, relative) => { // Use the mocked require. @@ -110,23 +109,6 @@ const getRuleFinder = proxyquire('../../src/lib/rule-finder', { } }); -function assertDeepEqual(a, b) { - if (supportsScopedPlugins) { - return assert.deepEqual(a, b); - } - - if (Array.isArray(b)) { - return assert.deepEqual(a, b.filter(s => !s.startsWith('@'))); - } - - const bWithoutScoped = Object.keys(b).filter(s => !s.startsWith('@')).reduce((acc, k) => { - acc[k] = b[k]; - return acc; - }, {}); - - return assert.deepEqual(a, bWithoutScoped); -} - const getRuleFinderForDedupeTests = proxyquire('../../src/lib/rule-finder', { eslint: { Linter: class { @@ -179,7 +161,7 @@ describe('rule-finder', function() { return noSpecifiedFile; }; const ruleFinder = await getRuleFinder(); - assertDeepEqual(ruleFinder.getUnusedRules(), ['bar-rule', 'baz-rule']); + assert.deepEqual(ruleFinder.getUnusedRules(), ['bar-rule', 'baz-rule']); }); it('no specifiedFile - unused rules including deprecated', async () => { @@ -187,7 +169,7 @@ describe('rule-finder', function() { return noSpecifiedFile; }; const ruleFinder = await getRuleFinder(null, {includeDeprecated: true}); - assertDeepEqual(ruleFinder.getUnusedRules(), ['bar-rule', 'baz-rule', 'old-rule']); + assert.deepEqual(ruleFinder.getUnusedRules(), ['bar-rule', 'baz-rule', 'old-rule']); }); it('no specifiedFile - current rules', async () => { @@ -195,7 +177,7 @@ describe('rule-finder', function() { return noSpecifiedFile; }; const ruleFinder = await getRuleFinder(); - assertDeepEqual(ruleFinder.getCurrentRules(), ['foo-rule']); + assert.deepEqual(ruleFinder.getCurrentRules(), ['foo-rule']); }); it('no specifiedFile - current rule config', async () => { @@ -203,7 +185,7 @@ describe('rule-finder', function() { return noSpecifiedFile; }; const ruleFinder = await getRuleFinder(); - assertDeepEqual(ruleFinder.getCurrentRulesDetailed(), {'foo-rule': [2]}); + assert.deepEqual(ruleFinder.getCurrentRulesDetailed(), {'foo-rule': [2]}); }); it('no specifiedFile - plugin rules', async () => { @@ -211,7 +193,7 @@ describe('rule-finder', function() { return noSpecifiedFile; }; const ruleFinder = await getRuleFinder(); - assertDeepEqual(ruleFinder.getPluginRules(), []); + assert.deepEqual(ruleFinder.getPluginRules(), []); }); it('no specifiedFile - all available rules', async () => { @@ -219,7 +201,7 @@ describe('rule-finder', function() { return noSpecifiedFile; }; const ruleFinder = await getRuleFinder(); - assertDeepEqual(ruleFinder.getAllAvailableRules(), ['bar-rule', 'baz-rule', 'foo-rule']); + assert.deepEqual(ruleFinder.getAllAvailableRules(), ['bar-rule', 'baz-rule', 'foo-rule']); }); it('no specifiedFile - all available rules without core', async () => { @@ -227,7 +209,7 @@ describe('rule-finder', function() { return noSpecifiedFile; }; const ruleFinder = await getRuleFinder(null, {omitCore: true}); - assertDeepEqual(ruleFinder.getAllAvailableRules(), []); + assert.deepEqual(ruleFinder.getAllAvailableRules(), []); }); it('no specifiedFile - all available rules including deprecated', async () => { @@ -235,12 +217,12 @@ describe('rule-finder', function() { return noSpecifiedFile; }; const ruleFinder = await getRuleFinder(null, {includeDeprecated: true}); - assertDeepEqual(ruleFinder.getAllAvailableRules(), ['bar-rule', 'baz-rule', 'foo-rule', 'old-rule']); + assert.deepEqual(ruleFinder.getAllAvailableRules(), ['bar-rule', 'baz-rule', 'foo-rule', 'old-rule']); }); it('specifiedFile (relative path) - unused rules', async () => { const ruleFinder = await getRuleFinder(specifiedFileRelative); - assertDeepEqual(ruleFinder.getUnusedRules(), [ + assert.deepEqual(ruleFinder.getUnusedRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/scoped-with-dash-plugin/bar-rule', '@scope/bar-rule', @@ -254,7 +236,7 @@ describe('rule-finder', function() { it('specifiedFile (relative path) - unused rules including deprecated', async () => { const ruleFinder = await getRuleFinder(specifiedFileRelative, {includeDeprecated: true}); - assertDeepEqual(ruleFinder.getUnusedRules(), [ + assert.deepEqual(ruleFinder.getUnusedRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/old-plugin-rule', '@scope-with-dash/scoped-with-dash-plugin/bar-rule', @@ -274,7 +256,7 @@ describe('rule-finder', function() { it('specifiedFile (relative path) - current rules', async () => { const ruleFinder = await getRuleFinder(specifiedFileRelative); - assertDeepEqual(ruleFinder.getCurrentRules(), [ + assert.deepEqual(ruleFinder.getCurrentRules(), [ '@scope-with-dash/foo-rule', '@scope-with-dash/scoped-with-dash-plugin/foo-rule', '@scope/foo-rule', @@ -286,7 +268,7 @@ describe('rule-finder', function() { it('specifiedFile (relative path) - current rules with ext', async () => { const ruleFinder = await getRuleFinder(specifiedFileRelative, { ext: ['.json'] }); - assertDeepEqual(ruleFinder.getCurrentRules(), [ + assert.deepEqual(ruleFinder.getCurrentRules(), [ '@scope-with-dash/foo-rule', '@scope-with-dash/scoped-with-dash-plugin/foo-rule', '@scope/foo-rule', @@ -298,7 +280,7 @@ describe('rule-finder', function() { it('specifiedFile (relative path) - current rules with ext without dot', async () => { const ruleFinder = await getRuleFinder(specifiedFileRelative, { ext: ['json'] }); - assertDeepEqual(ruleFinder.getCurrentRules(), [ + assert.deepEqual(ruleFinder.getCurrentRules(), [ '@scope-with-dash/foo-rule', '@scope-with-dash/scoped-with-dash-plugin/foo-rule', '@scope/foo-rule', @@ -310,12 +292,12 @@ describe('rule-finder', function() { it('specifiedFile (relative path) - current rules with ext not found', async () => { const ruleFinder = await getRuleFinder(specifiedFileRelative, { ext: ['.ts'] }); - assertDeepEqual(ruleFinder.getCurrentRules(), []); + assert.deepEqual(ruleFinder.getCurrentRules(), []); }); it('specifiedFile (relative path) - current rule config', async () => { const ruleFinder = await getRuleFinder(specifiedFileRelative); - assertDeepEqual(ruleFinder.getCurrentRulesDetailed(), { + assert.deepEqual(ruleFinder.getCurrentRulesDetailed(), { '@scope-with-dash/foo-rule': [2], '@scope-with-dash/scoped-with-dash-plugin/foo-rule': [2], '@scope/foo-rule': [2], @@ -327,7 +309,7 @@ describe('rule-finder', function() { it('specifiedFile (relative path) - plugin rules', async () => { const ruleFinder = await getRuleFinder(specifiedFileRelative); - assertDeepEqual(ruleFinder.getPluginRules(), [ + assert.deepEqual(ruleFinder.getPluginRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/foo-rule', '@scope-with-dash/scoped-with-dash-plugin/bar-rule', @@ -344,7 +326,7 @@ describe('rule-finder', function() { it('specifiedFile (relative path) - plugin rules including deprecated', async () => { const ruleFinder = await getRuleFinder(specifiedFileRelative, {includeDeprecated: true}); - assertDeepEqual(ruleFinder.getPluginRules(), [ + assert.deepEqual(ruleFinder.getPluginRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/foo-rule', '@scope-with-dash/old-plugin-rule', @@ -366,7 +348,7 @@ describe('rule-finder', function() { it('specifiedFile (relative path) - all available rules', async () => { const ruleFinder = await getRuleFinder(specifiedFileRelative); - assertDeepEqual( + assert.deepEqual( ruleFinder.getAllAvailableRules(), [ '@scope-with-dash/bar-rule', @@ -389,7 +371,7 @@ describe('rule-finder', function() { it('specifiedFile (relative path) - all available rules without core', async () => { const ruleFinder = await getRuleFinder(specifiedFileRelative, {omitCore: true}); - assertDeepEqual( + assert.deepEqual( ruleFinder.getAllAvailableRules(), [ '@scope-with-dash/bar-rule', @@ -409,7 +391,7 @@ describe('rule-finder', function() { it('specifiedFile (relative path) - all available rules including deprecated', async () => { const ruleFinder = await getRuleFinder(specifiedFileRelative, {includeDeprecated: true}); - assertDeepEqual( + assert.deepEqual( ruleFinder.getAllAvailableRules(), [ '@scope-with-dash/bar-rule', @@ -438,7 +420,7 @@ describe('rule-finder', function() { it('specifiedFile (absolute path) - unused rules', async () => { const ruleFinder = await getRuleFinder(specifiedFileAbsolute); - assertDeepEqual(ruleFinder.getUnusedRules(), [ + assert.deepEqual(ruleFinder.getUnusedRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/scoped-with-dash-plugin/bar-rule', '@scope/bar-rule', @@ -452,7 +434,7 @@ describe('rule-finder', function() { it('specifiedFile (absolute path) - unused rules', async () => { const ruleFinder = await getRuleFinder(specifiedFileAbsolute, {includeDeprecated: true}); - assertDeepEqual(ruleFinder.getUnusedRules(), [ + assert.deepEqual(ruleFinder.getUnusedRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/old-plugin-rule', '@scope-with-dash/scoped-with-dash-plugin/bar-rule', @@ -472,7 +454,7 @@ describe('rule-finder', function() { it('specifiedFile (absolute path) - current rules', async () => { const ruleFinder = await getRuleFinder(specifiedFileAbsolute); - assertDeepEqual(ruleFinder.getCurrentRules(), [ + assert.deepEqual(ruleFinder.getCurrentRules(), [ '@scope-with-dash/foo-rule', '@scope-with-dash/scoped-with-dash-plugin/foo-rule', '@scope/foo-rule', @@ -484,7 +466,7 @@ describe('rule-finder', function() { it('specifiedFile (absolute path) - current rule config', async () => { const ruleFinder = await getRuleFinder(specifiedFileAbsolute); - assertDeepEqual(ruleFinder.getCurrentRulesDetailed(), { + assert.deepEqual(ruleFinder.getCurrentRulesDetailed(), { '@scope-with-dash/foo-rule': [2], '@scope-with-dash/scoped-with-dash-plugin/foo-rule': [2], '@scope/foo-rule': [2], @@ -496,7 +478,7 @@ describe('rule-finder', function() { it('specifiedFile (absolute path) - plugin rules', async () => { const ruleFinder = await getRuleFinder(specifiedFileAbsolute); - assertDeepEqual(ruleFinder.getPluginRules(), [ + assert.deepEqual(ruleFinder.getPluginRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/foo-rule', '@scope-with-dash/scoped-with-dash-plugin/bar-rule', @@ -513,7 +495,7 @@ describe('rule-finder', function() { it('specifiedFile (absolute path) - plugin rules including deprecated', async () => { const ruleFinder = await getRuleFinder(specifiedFileAbsolute, {includeDeprecated: true}); - assertDeepEqual(ruleFinder.getPluginRules(), [ + assert.deepEqual(ruleFinder.getPluginRules(), [ '@scope-with-dash/bar-rule', '@scope-with-dash/foo-rule', '@scope-with-dash/old-plugin-rule', @@ -535,7 +517,7 @@ describe('rule-finder', function() { it('specifiedFile (absolute path) - all available rules', async () => { const ruleFinder = await getRuleFinder(specifiedFileAbsolute); - assertDeepEqual( + assert.deepEqual( ruleFinder.getAllAvailableRules(), [ '@scope-with-dash/bar-rule', @@ -558,7 +540,7 @@ describe('rule-finder', function() { it('specifiedFile (absolute path) - all available rules including deprecated', async () => { const ruleFinder = await getRuleFinder(specifiedFileAbsolute, {includeDeprecated: true}); - assertDeepEqual( + assert.deepEqual( ruleFinder.getAllAvailableRules(), [ '@scope-with-dash/bar-rule', @@ -587,7 +569,7 @@ describe('rule-finder', function() { it('specifiedFile (absolute path) without rules - plugin rules', async () => { const ruleFinder = await getRuleFinder(noRulesFile); - assertDeepEqual(ruleFinder.getPluginRules(), [ + assert.deepEqual(ruleFinder.getPluginRules(), [ 'plugin/bar-rule', 'plugin/baz-rule', 'plugin/foo-rule' @@ -596,7 +578,7 @@ describe('rule-finder', function() { it('dedupes plugin rules - all available rules', async () => { const ruleFinder = await getRuleFinderForDedupeTests(noDuplicateRulesFiles); - assertDeepEqual(ruleFinder.getAllAvailableRules(), [ + assert.deepEqual(ruleFinder.getAllAvailableRules(), [ 'bar-rule', 'foo-rule', 'plugin/duplicate-bar-rule', @@ -606,7 +588,7 @@ describe('rule-finder', function() { it('dedupes plugin rules - unused rules', async () => { const ruleFinder = await getRuleFinderForDedupeTests(noDuplicateRulesFiles); - assertDeepEqual(ruleFinder.getUnusedRules(), [ + assert.deepEqual(ruleFinder.getUnusedRules(), [ 'bar-rule', 'plugin/duplicate-foo-rule' ]); @@ -614,12 +596,12 @@ describe('rule-finder', function() { it('specifiedFile (absolute path) without deprecated rules - deprecated rules', async () => { const ruleFinder = await getRuleFinder(specifiedFileAbsolute); - assertDeepEqual(ruleFinder.getDeprecatedRules(), []); + assert.deepEqual(ruleFinder.getDeprecatedRules(), []); }); it('specifiedFile (absolute path) with deprecated rules - deprecated rules', async () => { const ruleFinder = await getRuleFinder(usingDeprecatedRulesFile); - assertDeepEqual(ruleFinder.getDeprecatedRules(), [ + assert.deepEqual(ruleFinder.getDeprecatedRules(), [ '@scope-with-dash/old-plugin-rule', '@scope-with-dash/scoped-with-dash-plugin/old-plugin-rule', '@scope/old-plugin-rule', From c3576b5689cad4760045bad74df624a59ad8d0ba Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 7 Nov 2021 22:59:18 -0800 Subject: [PATCH 4/6] refactor: remove unnecessary `path-is-absolute` --- package.json | 1 - src/lib/rule-finder.js | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/package.json b/package.json index 793e831..4bfc5e0 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ "cliui": "^3.2.0", "eslint-rule-documentation": "^1.0.23", "glob": "^7.1.6", - "path-is-absolute": "^1.0.1", "which": "^1.3.1", "window-size": "^0.3.0", "yargs": "^8.0.2" diff --git a/src/lib/rule-finder.js b/src/lib/rule-finder.js index a85a4ca..6c14fa5 100644 --- a/src/lib/rule-finder.js +++ b/src/lib/rule-finder.js @@ -2,14 +2,13 @@ const path = require('path'); const eslint = require('eslint'); const glob = require('glob'); -const isAbsolute = require('path-is-absolute'); const difference = require('./array-diff'); const getSortedRules = require('./sort-rules'); const normalizePluginName = require('./normalize-plugin-name'); function _getConfigFile(specifiedFile) { if (specifiedFile) { - if (isAbsolute(specifiedFile)) { + if (path.isAbsolute(specifiedFile)) { return specifiedFile; } return path.join(process.cwd(), specifiedFile); From 1e940a928cda4c2ef666fc1954d2ce21cfd5a87b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 7 Nov 2021 23:05:28 -0800 Subject: [PATCH 5/6] deps: update `yargs` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4bfc5e0..817cb64 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "glob": "^7.1.6", "which": "^1.3.1", "window-size": "^0.3.0", - "yargs": "^8.0.2" + "yargs": "^16.2.0" }, "devDependencies": { "all-contributors-cli": "^4.11.2", From e95f4adb980ce7aaf0c24ba6eb75aefc36764f30 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 7 Nov 2021 23:06:41 -0800 Subject: [PATCH 6/6] deps: update `glob` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 817cb64..61c085a 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "dependencies": { "cliui": "^3.2.0", "eslint-rule-documentation": "^1.0.23", - "glob": "^7.1.6", + "glob": "^7.2.0", "which": "^1.3.1", "window-size": "^0.3.0", "yargs": "^16.2.0"