Skip to content

Commit

Permalink
feat: Support Eslint 9 (#5462)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Apr 9, 2024
1 parent ab856ff commit bdc18a2
Show file tree
Hide file tree
Showing 64 changed files with 2,327 additions and 303 deletions.
20 changes: 13 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const config = {
},
extends: [
'eslint:recommended',
'plugin:node/recommended',
'plugin:n/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:promise/recommended',
Expand Down Expand Up @@ -61,13 +61,13 @@ const config = {
'no-restricted-modules': 'error',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
// This is caught by 'import/no-unresolved'
'node/no-missing-import': [
'n/no-missing-import': [
'off',
{
tryExtensions: ['.js', '.d.ts', '.ts'],
},
],
'node/no-unsupported-features/es-syntax': 'off',
'n/no-unsupported-features/es-syntax': 'off',
'import/no-unresolved': 'off',
'@typescript-eslint/consistent-type-imports': 'error',
// 'import/order': 'error',
Expand All @@ -93,7 +93,7 @@ const config = {
sourceType: 'module',
},
rules: {
'node/no-unsupported-features/es-syntax': 'off',
'n/no-unsupported-features/es-syntax': 'off',
},
},
{
Expand All @@ -109,9 +109,15 @@ const config = {
'**/src/perf/**',
],
rules: {
'node/no-extraneous-import': 'off',
'node/no-extraneous-require': 'off',
'node/no-unpublished-import': 'off',
'n/no-extraneous-import': 'off',
'n/no-extraneous-require': 'off',
'n/no-unpublished-import': 'off',
},
},
{
files: ['**/eslint.config.js'],
rules: {
'import/no-unresolved': 'off',
},
},
],
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"devDependencies": {
"@cspell/dict-markdown": "^2.0.1",
"@cspell/eslint-plugin": "workspace:*",
"@eslint/eslintrc": "^3.0.2",
"@internal/scripts": "workspace:*",
"@lerna-lite/cli": "^3.3.2",
"@lerna-lite/publish": "^3.3.2",
Expand All @@ -104,15 +105,16 @@
"@rollup/plugin-typescript": "^11.1.6",
"@tsconfig/node18": "^18.2.4",
"@types/node": "^18.19.30",
"@typescript-eslint/eslint-plugin": "^7.5.0",
"@typescript-eslint/parser": "^7.5.0",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"@vitest/coverage-istanbul": "^1.4.0",
"conventional-changelog-conventionalcommits": "^7.0.2",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-n": "^17.1.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.1.1",
Expand All @@ -128,6 +130,7 @@
"ts2mjs": "^3.0.0",
"tslib": "^2.6.2",
"typescript": "^5.4.4",
"typescript-eslint": "^7.6.0",
"vite": "^5.2.8",
"vitest": "^1.4.0"
}
Expand Down
135 changes: 135 additions & 0 deletions packages/cspell-eslint-plugin/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// import { fileURLToPath } from 'node:url';

import eslint from '@eslint/js';
import nodePlugin from 'eslint-plugin-n';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import tsEslint from 'typescript-eslint';

// import { FlatCompat } from '@eslint/eslintrc';

// const __dirname = fileURLToPath(new URL('.', import.meta.url));

// const compat = new FlatCompat({
// baseDirectory: __dirname,
// });

export default tsEslint.config(
nodePlugin.configs['flat/recommended'],
{
rules: {
'n/exports-style': ['error', 'module.exports'],
'n/no-extraneous-import': 'error',
'n/no-unpublished-import': [
'error',
{
ignoreTypeImport: true,
},
],
},
},
eslint.configs.recommended,
...tsEslint.configs.recommended,
{
ignores: [
'**/[Ss]amples/**', // cspell:disable-line
'**/[Tt]emp/**',
'**/.temp/**',
'**/*.d.ts',
'**/*.d.cts',
'**/*.d.mts',
'**/src/lib*/*.cjs',
'**/*.map',
'**/coverage/**',
'**/cspell-default.config.js',
'**/dist/**',
'**/dist.*/**',
'tools/*/lib/**',
'**/node_modules/**',
'**/.docusaurus/**',
'docs/_site/**',
'docs/docsV2/**',
'docs/types/cspell-types/**',
'integration-tests/repositories/**',
'packages/*/fixtures/**',
'packages/*/esm/**',
'test-fixtures/**',
'test-packages/cspell-eslint-plugin/**',
'test-packages/yarn/**',
'website',
'**/lib-bundled/**',
'website/**', // checked with a different config

// Ignore cspell-eslint-plugin
'fixtures/**',
],
},
{
plugins: {
'simple-import-sort': simpleImportSort,
},
rules: {
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
},
},
{
files: ['**/*.ts', '**/*.mts', '**/*.cts'],
rules: {
'no-restricted-modules': 'error',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
// This is caught by 'import/no-unresolved'
'node/no-missing-import': [
'off',
{
tryExtensions: ['.js', '.d.ts', '.ts'],
},
],
'node/no-unsupported-features/es-syntax': 'off',
// 'import/no-unresolved': 'off',
'@typescript-eslint/consistent-type-imports': 'error',
},
},
{
files: ['**/*.ts', '**/*.mts', '**/*.cts'],
rules: {
'node/no-missing-import': [
'off',
{
tryExtensions: ['.js', '.d.ts', '.ts'],
},
],
'node/no-unsupported-features/es-syntax': 'off',
'import/no-unresolved': 'off',
},
},
{
files: ['packages/cspell-pipe/**/*.ts'],
rules: {
'import/extensions': ['error', 'ignorePackages'],
},
},
{
files: ['**/*.js', '**/*.mjs'],
rules: {
'node/no-unsupported-features/es-syntax': 'off',
},
},
{
files: [
'vitest.config.*',
'**/*.test.*',
'**/test.*',
'**/rollup.*',
'**/*.spec.*',
'**/test-helpers/**',
'**/test-utils/**',
'**/src/test/**',
'**/src/perf/**',
],
rules: {
'node/no-extraneous-import': 'off',
'node/no-extraneous-require': 'off',
'node/no-unpublished-import': 'off',
},
},
);
35 changes: 0 additions & 35 deletions packages/cspell-eslint-plugin/fixtures/issue-4870/.eslintrc.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import eslint from '@eslint/js';
import nodePlugin from 'eslint-plugin-n';
import cspellRecommended from '@cspell/eslint-plugin/recommended';

/**
* @type { import("eslint").Linter.FlatConfig[] }
*/
const config = [
eslint.configs.recommended,
nodePlugin.configs['flat/recommended-module'],
{
rules: {
'n/no-extraneous-import': 'off',
'n/no-unpublished-import': 'off',
},
},
cspellRecommended,
{
rules: {
'@cspell/spellchecker': [
'warn',
{
debugMode: false,
autoFix: true,
cspell: {
dictionaries: ['business-terminology'],
dictionaryDefinitions: [
{
name: 'business-terminology',
path: './dictionaries/business-terminology.txt',
},
],
},
},
],
},
},
];

export default config;
23 changes: 15 additions & 8 deletions packages/cspell-eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"!**/*.map"
],
"scripts": {
"bt": "pnpm build && pnpm test",
"build": "pnpm build:schema && pnpm build:src",
"build:src": "tsc -b ./tsconfig.json",
"build:schema": "ts-json-schema-generator --no-top-ref --expose none --path src/common/options.cts --type Options -o ./assets/options.schema.json",
Expand All @@ -59,7 +60,7 @@
"clean-build": "pnpm run clean && pnpm run build",
"coverage": "echo coverage",
"test-watch": "pnpm run test -- --watch",
"test": "npx mocha --timeout 10000 \"dist/**/*.test.cjs\""
"test": "npx mocha --timeout 10000 \"dist/**/*.test.mjs\""
},
"repository": {
"type": "git",
Expand All @@ -73,23 +74,29 @@
"node": ">=18"
},
"devDependencies": {
"@types/eslint": "^8.56.7",
"@eslint/eslintrc": "^3.0.2",
"@eslint/js": "^9.0.0",
"@types/estree": "^1.0.5",
"@types/mocha": "^10.0.6",
"@typescript-eslint/eslint-plugin": "^7.5.0",
"@typescript-eslint/parser": "^7.5.0",
"@typescript-eslint/types": "^7.5.0",
"@typescript-eslint/typescript-estree": "^7.5.0",
"eslint": "^8.57.0",
"@typescript-eslint/parser": "^7.6.0",
"@typescript-eslint/types": "^7.6.0",
"eslint": "^9.0.0",
"eslint-plugin-n": "^17.1.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-simple-import-sort": "^12.0.0",
"globals": "^15.0.0",
"mocha": "^10.4.0",
"ts-json-schema-generator": "^1.5.0",
"typescript": "^5.4.4"
"typescript": "^5.4.4",
"typescript-eslint": "^7.6.0"
},
"dependencies": {
"@cspell/cspell-types": "workspace:*",
"cspell-lib": "workspace:*",
"estree-walker": "^3.0.3",
"synckit": "^0.9.0"
},
"peerDependencies": {
"eslint": "^7 || ^8 || ^9"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function create(context: Rule.RuleContext): Rule.RuleListener {
const data = {
word,
};
const code = context.sourceCode || context.getSourceCode();
const code = contextSourceCode(context);
const startPos = code.getLocFromIndex(start);
const endPos = code.getLocFromIndex(end);
const loc = { start: startPos, end: endPos };
Expand Down Expand Up @@ -149,11 +149,15 @@ function logContext(log: typeof console.log, context: Rule.RuleContext) {
cwd: context.cwd,
filename: context.filename,
physicalFilename: context.physicalFilename,
scope: context.getScope().type,
// scope: context.getScope().type,
options: context.options.length === 1 ? context.options[0] : context.options,
});
}

function contextSourceCode(context: Rule.RuleContext): Rule.RuleContext['sourceCode'] {
return context.sourceCode || context.getSourceCode();
}

export const meta = { name: '@cspell' } as const;

const recommended: ESLint.ConfigData = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'eslint-plugin-react';
Loading

0 comments on commit bdc18a2

Please sign in to comment.