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

feat: support ESLint 8.x #11

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/checks.yaml
Expand Up @@ -33,14 +33,14 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [10.x, 12.x, 13.x, 14.x]
eslint-version: [6, 7]
node-version: [12, 14, 16]
eslint-version: [6, 7, 8]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2-beta
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: install with eslint v${{matrix.eslint-version }}
Expand All @@ -66,9 +66,9 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
- uses: actions/setup-node@v2
with:
node-version: 12.x
node-version: 16
- name: install
run: npm ci
- name: prettier
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Expand Up @@ -14,9 +14,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
- uses: actions/setup-node@v2
with:
node-version: '12.x'
node-version: 16

- uses: actions/cache@v2
with:
Expand Down
1,199 changes: 715 additions & 484 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions package.json
Expand Up @@ -79,7 +79,7 @@
]
},
"dependencies": {
"@typescript-eslint/experimental-utils": "^4.11.1",
"@typescript-eslint/experimental-utils": "^5.0.0-0",
"require-relative": "^0.8.7"
},
"devDependencies": {
Expand All @@ -93,25 +93,25 @@
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@types/dedent": "^0.7.0",
"@types/eslint": "^7.2.6",
"@types/eslint": "^7.28.0",
"@types/jest": "^26.0.19",
"@types/node": "^12.19.11",
"@types/prettier": "^2.1.6",
"@types/require-relative": "^0.8.0",
"@typescript-eslint/eslint-plugin": "^4.11.1",
"@typescript-eslint/parser": "^4.11.1",
"@typescript-eslint/eslint-plugin": "^5.0.0-0",
"@typescript-eslint/parser": "^5.0.0-0",
"babel-jest": "^26.6.3",
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
"dedent": "^0.7.0",
"eslint": "^7.17.0",
"eslint-config-ackama": "^2.0.1",
"eslint": "^8.0.0",
"eslint-config-ackama": "^2.2.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-eslint-plugin": "^2.3.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-jest-formatting": "^2.0.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^25.0.1",
"eslint-plugin-jest-formatting": "^2.0.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.0",
"eslint-plugin-prettier": "^3.4.1",
"husky": "^4.3.6",
"jest": "^26.6.3",
"jest-runner-eslint": "^0.10.0",
Expand All @@ -124,10 +124,10 @@
"typescript": "^4.1.3"
},
"peerDependencies": {
"eslint": ">=5"
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
},
"engines": {
"node": ">=10"
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"release": {
"plugins": [
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
@@ -1,4 +1,4 @@
import ESLint from 'eslint';
import { Linter, Rule } from 'eslint';
import { readdirSync } from 'fs';
import { join, parse } from 'path';

Expand All @@ -16,7 +16,7 @@ const rules = readdirSync(rulesDir)
);

const allRules = Object.keys(rules).reduce<
Record<string, ESLint.Linter.RuleLevel>
Record<string, Linter.RuleLevel>
>(
(theRules, key) => ({
...theRules,
Expand All @@ -25,7 +25,7 @@ const allRules = Object.keys(rules).reduce<
{}
);

interface PluginConfig extends ESLint.Linter.Config {
interface PluginConfig extends Linter.Config {
plugins: ['eslint-config'];
}

Expand All @@ -35,7 +35,7 @@ const plugin: {
PluginConfig & Required<Pick<PluginConfig, 'rules'>>
> &
Record<string, PluginConfig>;
rules: Record<string, ESLint.Rule.RuleModule>;
rules: Record<string, Rule.RuleModule>;
} = {
configs: {
'all': {
Expand Down
1 change: 0 additions & 1 deletion src/rules/no-deprecated-rules.ts
Expand Up @@ -22,7 +22,6 @@ export = ESLintUtils.RuleCreator(name => name)({
type: 'problem',
docs: {
description: 'Checks for usage of deprecated eslint rules',
category: 'Best Practices',
recommended: 'warn',
suggestion: true
},
Expand Down
1 change: 0 additions & 1 deletion src/rules/no-invalid-config.ts
Expand Up @@ -24,7 +24,6 @@ export = ESLintUtils.RuleCreator(name => name)({
type: 'problem',
docs: {
description: 'Checks that the config exported by a file is valid',
category: 'Best Practices',
recommended: 'error'
},
messages: {
Expand Down
1 change: 0 additions & 1 deletion src/rules/no-unknown-rules.ts
Expand Up @@ -7,7 +7,6 @@ export = ESLintUtils.RuleCreator(name => name)({
type: 'problem',
docs: {
description: 'Ensures that all rules are known',
category: 'Best Practices',
recommended: 'error'
},
messages: {
Expand Down
1 change: 0 additions & 1 deletion src/rules/sort-rules.ts
Expand Up @@ -50,7 +50,6 @@ export = ESLintUtils.RuleCreator(name => name)({
type: 'problem',
docs: {
description: 'Ensures that rules are sorted in a consistent order',
category: 'Best Practices',
recommended: false
},
fixable: 'code',
Expand Down
39 changes: 16 additions & 23 deletions src/rules/utils.ts
@@ -1,4 +1,4 @@
import ESLint from 'eslint';
import { CLIEngine, Linter } from 'eslint';
import requireRelative from 'require-relative';
import { runInNewContext } from 'vm';

Expand Down Expand Up @@ -32,25 +32,25 @@ const relativeRequire = (name: string): unknown =>
relativeRequire.resolve = (name: string): string =>
requireRelative.resolve(name, process.cwd());

const compileConfigCodeCache = new Map<string, ESLint.Linter.Config>();
const compileConfigCodeCache = new Map<string, Linter.Config>();

const compileConfigCode = (fileCode: string): ESLint.Linter.Config => {
const compileConfigCode = (fileCode: string): Linter.Config => {
return getsertCache(
compileConfigCodeCache,
fileCode,
() =>
(runInNewContext(fileCode, {
module: { exports: {} },
require: relativeRequire
}) ?? {}) as ESLint.Linter.Config,
}) ?? {}) as Linter.Config,
'compileConfigCode'
);
};

const createCliEngineCache = new Map<string, ESLint.CLIEngine>();
const createCliEngineCache = new Map<string, CLIEngine>();

const createCLIEngine = (config: ESLint.Linter.Config): ESLint.CLIEngine => {
const extraConfig: ESLint.Linter.Config = {
const createCLIEngine = (config: Linter.Config): CLIEngine => {
const extraConfig: Linter.Config = {
parserOptions: {
...config.parserOptions,
project: require.resolve('../../tsconfig.fake.json'),
Expand All @@ -72,7 +72,7 @@ const createCLIEngine = (config: ESLint.Linter.Config): ESLint.CLIEngine => {
createCliEngineCache,
JSON.stringify(config),
() =>
new ESLint.CLIEngine({
new CLIEngine({
useEslintrc: false,
ignorePath: pathToBlankFile,
ignorePattern: ['!node_modules/*'],
Expand All @@ -88,7 +88,7 @@ const createCLIEngine = (config: ESLint.Linter.Config): ESLint.CLIEngine => {
};

interface ConfigInfo {
deprecatedRules: ESLint.CLIEngine.DeprecatedRuleUse[];
deprecatedRules: CLIEngine.DeprecatedRuleUse[];
unknownRules: string[];
errors: ESLintError[];
}
Expand All @@ -107,10 +107,7 @@ const ensureArray = <T>(v: T | T[] = []): T[] => (Array.isArray(v) ? v : [v]);
* Merging is done at the top level only, and based on explicit named properties,
* so any additional properties on either config will be lost.
*/
const mergeConfigs = (
a: ESLint.Linter.Config,
b: ESLint.Linter.Config
): ESLint.Linter.Config => ({
const mergeConfigs = (a: Linter.Config, b: Linter.Config): Linter.Config => ({
parser: b.parser ?? a.parser,
parserOptions: { ...a.parserOptions, ...b.parserOptions },
processor: b.processor ?? a.processor,
Expand All @@ -126,9 +123,7 @@ const mergeConfigs = (
rules: { ...a.rules, ...b.rules }
});

const extractRelevantConfigs = (
config: ESLint.Linter.Config
): ESLint.Linter.Config[] => [
const extractRelevantConfigs = (config: Linter.Config): Linter.Config[] => [
{ ...config, overrides: [] },
...(config.overrides ?? [])
.map(override =>
Expand Down Expand Up @@ -279,9 +274,9 @@ const parseESLintError = (error: Error): ESLintError => {
};

const followErrorPathToConfig = (
config: ESLint.Linter.Config,
config: Linter.Config,
error: ESLintError
): ESLint.Linter.Config => {
): Linter.Config => {
if (!error.path || !config.overrides) {
return config;
}
Expand All @@ -296,7 +291,7 @@ const followErrorPathToConfig = (
};

const tryRemoveErrorPointFromConfig = (
config: ESLint.Linter.Config,
config: Linter.Config,
error: ESLintError
): boolean => {
const configToDeleteFrom = followErrorPathToConfig(config, error);
Expand Down Expand Up @@ -350,9 +345,7 @@ const tryRemoveErrorPointFromConfig = (
return false;
};

const collectConfigInfoFromESLint = (
config: ESLint.Linter.Config
): ConfigInfo => {
const collectConfigInfoFromESLint = (config: Linter.Config): ConfigInfo => {
const theConfig = { rules: {}, ...config };
const errors: ESLintError[] = [];
let counter = 0;
Expand Down Expand Up @@ -406,7 +399,7 @@ const collectConfigInfoCache = new Map<string, ConfigInfo>();
* Info about any `overrides` the `config` might have will be collected and
* merged into the returned info object.
*/
const collectConfigInfo = (config: ESLint.Linter.Config): ConfigInfo => {
const collectConfigInfo = (config: Linter.Config): ConfigInfo => {
return getsertCache(
collectConfigInfoCache,
JSON.stringify(config),
Expand Down
2 changes: 0 additions & 2 deletions test/helpers.ts
Expand Up @@ -80,7 +80,6 @@ export const mockEslintPluginPrettier = (): void => {
type: 'problem',
docs: {
description: 'Fake rule that is deprecated, for use in testing',
category: 'Best Practices',
recommended: 'warn'
},
deprecated: true,
Expand All @@ -99,7 +98,6 @@ export const mockEslintPluginPrettier = (): void => {
type: 'problem',
docs: {
description: 'Fake rule that always throws, for use in testing',
category: 'Best Practices',
recommended: 'warn'
},
messages: {},
Expand Down