Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

breaking: support ESLint 8.x #337

Merged
merged 6 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
"node": true
},
"parserOptions": {
"ecmaFeatures": {
"impliedStrict": true
},
"ecmaVersion": 2017
"ecmaVersion": 2018
},
"plugins": ["json"],
"root": true
Expand Down
41 changes: 12 additions & 29 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,20 @@ jobs:
matrix:
node-version: ${{ fromJson(needs.matrix.outputs.majors) }}
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
- node-version: 13
eslint: 8
- node-version: 11
eslint: 8
- node-version: 10
eslint: 8

steps:
- uses: actions/checkout@v2
Expand All @@ -61,12 +48,8 @@ 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
- run: npm ls > /dev/null
- run: npm run cover
Expand Down
33 changes: 25 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,23 @@
"dependencies": {
"cliui": "^3.2.0",
"eslint-rule-documentation": "^1.0.23",
"glob": "^7.1.6",
"path-is-absolute": "^1.0.1",
"glob": "^7.2.0",
"which": "^1.3.1",
"window-size": "^0.3.0",
"yargs": "^8.0.2"
"yargs": "^16.2.0"
},
"devDependencies": {
"ajv": "^5 || ^6",
"all-contributors-cli": "^4.11.2",
"aud": "^1.1.5",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"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": "^7 || ^8.2.0",
"eslint-plugin-json": "^3.1.0",
"ghooks": "^2.0.4",
"in-publish": "^2.0.1",
"mocha": "^3.5.3",
Expand All @@ -64,7 +63,7 @@
"validate-commit-msg": "^2.14.0"
},
"peerDependencies": {
"eslint": "^3.12.0 || ^4 || ^5 || ^6 || ^7"
"eslint": "^7 || ^8.2.0"
},
"nyc": {
"exclude": [
Expand All @@ -76,6 +75,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"
}
Expand All @@ -89,6 +106,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"
}
}
18 changes: 14 additions & 4 deletions src/bin/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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]
)
};
}
Expand All @@ -94,3 +97,10 @@ function rulesDifference(a, b) {
)
);
}

process.exit(0);

})().catch(/* istanbul ignore next */(e) => {
console.error(e);
process.exit(1);
});
9 changes: 8 additions & 1 deletion src/bin/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
});
67 changes: 1 addition & 66 deletions src/lib/normalize-plugin-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function _getNormalizer() {
}

const eslintVersionFunctions = [
// eslint >= 7.0.0
// eslint >= 7.8.0
function () {
const ESLintExports = require('eslint');

Expand Down Expand Up @@ -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) {
Expand Down
Loading