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@9 and flat config #519

Merged
merged 2 commits into from
Jun 8, 2024
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
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

80 changes: 0 additions & 80 deletions .eslintrc.js

This file was deleted.

61 changes: 30 additions & 31 deletions README.md

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';

export default defineConfig([
js.configs.recommended,
...tseslint.configs.recommended,
{ ignores: ['**/dist', '.cache-eslint-remote-tester', 'docs'] },
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
},
{
files: ['*config*', 'ci/**', '**/test/**/*.ts*', '**/*.js', '**/*.cjs'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
languageOptions: {
globals: {
require: 'readonly',
module: 'readonly',
process: 'readonly',
},
},
},
eslintPluginPrettierRecommended,
]);

/** @param config {import('eslint').Linter.FlatConfig} */
function defineConfig(config) {
return config;
}
20 changes: 6 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,20 @@
"test:integration": "pnpm --recursive --stream --reporter-hide-prefix test:integration",
"test:smoke": "pnpm --recursive --stream --reporter-hide-prefix test:smoke",
"generate:changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"lint": "eslint . --max-warnings 0 --ext .js,.ts,.tsx && publint packages/**",
"lint": "eslint . --max-warnings 0 && publint packages/*",
"publish-pr": "pkg-pr-new publish --compact ./packages/eslint-remote-tester ./packages/repositories"
},
"repository": {
"type": "git",
"url": "https://github.com/AriPerkkio/eslint-remote-tester"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^7.11.0",
"@typescript-eslint/parser": "^7.11.0",
"@eslint/js": "^9.3.0",
"conventional-changelog-cli": "^5.0.0",
"eslint": "^8.57.0",
"eslint": "^9.3.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-local-rules": "^2.0.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.2",
"eslint-plugin-react-hooks": "^4.6.2",
"pkg-pr-new": "^0.0.5",
"pkg-pr-new": "^0.0.8",
"prettier": "^3.2.5",
"publint": "^0.2.8",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"typescript-eslint": "^7.11.0"
},
"keywords": [
"eslint",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
import js from '@eslint/js';

/** @type {import('./src/config/types').Config} */
const config = {
repositories: [
'AriPerkkio/eslint-remote-tester-integration-test-target',
'AriPerkkio/aria-live-capture',
Expand All @@ -17,20 +20,7 @@ module.exports = {

concurrentTasks: 3,

eslintrc: {
root: true,
env: {
es6: true,
},
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
extends: ['eslint:recommended'],
},
eslintConfig: [js.configs.recommended],

cache: true,

Expand Down Expand Up @@ -61,3 +51,5 @@ module.exports = {
*/
onComplete: undefined,
};

export default config;
36 changes: 36 additions & 0 deletions packages/eslint-remote-tester/eslint-remote-tester.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import js from '@eslint/js';
import type { Config } from './src/types';

export default defineConfig({
repositories: [
'AriPerkkio/eslint-remote-tester-integration-test-target',
'AriPerkkio/aria-live-capture',
'AriPerkkio/extend-to-be-announced',
'AriPerkkio/state-mgmt-examples',
'AriPerkkio/suspense-examples',
],

extensions: ['js', 'jsx', 'ts', 'tsx'],

maxFileSizeBytes: undefined,

rulesUnderTesting: [],

resultParser: undefined,

concurrentTasks: 3,

eslintConfig: [js.configs.recommended] as any,

cache: true,

compare: false,

updateComparisonReference: true,

onComplete: undefined,
});

function defineConfig(config: Config) {
return config;
}
35 changes: 24 additions & 11 deletions packages/eslint-remote-tester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.js",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
"types": "./dist/types.d.ts",
"exports": {
".": {
"types": "./dist/types.d.ts",
"import": "./dist/index.js"
},
"./github-actions": {
"types": "./dist/exports-for-compare-action.d.ts",
"import": "./dist/exports-for-compare-action.js"
}
},
"files": [
"dist"
],
Expand All @@ -22,9 +31,8 @@
"scripts": {
"prebuild": "rm -rf ./dist",
"build": "tsc --project tsconfig.prod.json",
"start": "node dist --config eslint-remote-tester.config.cjs",
"start": "node dist --config eslint-remote-tester.config.js",
"start:memory-limit-crash": "NODE_OPTIONS=--max_old_space_size=50 node dist",
"lint": "eslint . --max-warnings 0 --ext .js,.ts,.tsx && publint",
"test:integration": "vitest run --config test/integration/vitest.config.integration.ts",
"test:smoke": "vitest run --config test/smoke/vitest.config.smoke.ts",
"validate": "pnpm build && pnpm lint && pnpm test && pnpm test:integration"
Expand All @@ -45,29 +53,34 @@
"simple-git": "^3.24.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@types/babel__code-frame": "^7.0.6",
"@types/eslint": "^8.56.10",
"@types/node": "^20.12.12",
"@types/object-hash": "^3.0.6",
"@types/react": "^17.0.80",
"@typescript-eslint/eslint-plugin": "^7.11.0",
"@typescript-eslint/parser": "^7.11.0",
"conventional-changelog-cli": "^5.0.0",
"eslint": "^8.57.0",
"eslint": "^9.3.0",
"eslint-plugin-local-rules": "^2.0.1",
"eslint-remote-tester-repositories": "workspace:*",
"importx": "^0.3.5",
"ink-testing-library": "^2.1.0",
"jiti": "^1.21.3",
"node-pty": "^1.0.0",
"strip-ansi": "^6.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"vitest": "^1.6.0"
},
"peerDependencies": {
"eslint": ">=7",
"ts-node": ">=9.0.0"
"eslint": ">=9",
"importx": ">=0.3.5",
"jiti": ">=1"
},
"peerDependenciesMeta": {
"ts-node": {
"importx": {
"optional": true
},
"jiti": {
"optional": true
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-remote-tester/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { loadConfig } from './load.js';
import { WorkerData } from '../engine/types.js';

const DEFAULT_CONFIGURATION_FILE_NAME = 'eslint-remote-tester.config';
const DEFAULT_CONFIGURATION_FILE_JS = `${DEFAULT_CONFIGURATION_FILE_NAME}.cjs`;
const DEFAULT_CONFIGURATION_FILE_JS = `${DEFAULT_CONFIGURATION_FILE_NAME}.js`;
const DEFAULT_CONFIGURATION_FILE_TS = `${DEFAULT_CONFIGURATION_FILE_NAME}.ts`;
const CLI_ARGS_CONFIG = ['-c', '--config'];

Expand Down Expand Up @@ -48,7 +48,7 @@ if (!fs.existsSync(CONFIGURATION_FILE)) {
process.exit();
}

const configFileContents = loadConfig(path.resolve(CONFIGURATION_FILE));
const configFileContents = await loadConfig(path.resolve(CONFIGURATION_FILE));
const config = getConfigWithDefaults(configFileContents);

export default config;
54 changes: 26 additions & 28 deletions packages/eslint-remote-tester/src/config/load.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
import { createRequire } from 'node:module';
import type { Service, RegisterOptions } from 'ts-node';

let registerer: Service | null = null;
const require = createRequire(import.meta.url);

/* istanbul ignore next */
const interopRequireDefault = (obj: any): { default: any } =>
obj && obj.__esModule ? obj : { default: obj };

/** @internal */
export const loadTSConfig = (configPath: string) => {
export const loadTSConfig = async (configPath: string) => {
let importx: typeof import('importx') | undefined = undefined;
let jiti: typeof import('jiti') | undefined = undefined;

try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
registerer ||= require('ts-node').register({
moduleTypes: { '**/*.ts': 'cjs' },
} satisfies RegisterOptions) as Service;
} catch (e: any) {
if (e.code === 'MODULE_NOT_FOUND') {
importx = await import('importx');
} catch {
try {
jiti = await import('jiti');
} catch {
throw new Error(
`'ts-node' is required for TypeScript configuration files. Make sure it is installed\nError: ${e.message}`
"'jiti' or 'importx' is required for loading TypeScript configuration files. Make sure to install one of them."
);
}

throw e;
}

registerer.enabled(true);

// eslint-disable-next-line @typescript-eslint/no-var-requires
const configObject = interopRequireDefault(require(configPath)).default;
if (importx) {
const config = await importx.import(configPath, import.meta.url);
return config.default;
}

registerer.enabled(false);
if (jiti) {
return jiti.default(import.meta.url, {
interopDefault: true,
esmResolve: true,
})(configPath);
}

return configObject;
throw new Error(
"'jiti' or 'importx' is required for loading TypeScript configuration files. Make sure to install one of them."
);
};

export const loadConfig = (configPath: string) => {
export const loadConfig = async (configPath: string) => {
if (configPath.endsWith('.ts')) {
return loadTSConfig(configPath);
}

return require(configPath);
const { default: config } = await import(configPath);
return config;
};
Loading