Skip to content

Commit 2986bc8

Browse files
authored
Use FlatESLint in integration test (#1915)
1 parent 3c7d7c0 commit 2986bc8

File tree

4 files changed

+134
-99
lines changed

4 files changed

+134
-99
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ jobs:
7777
- "7"
7878
- "8"
7979
- "9"
80-
- "10"
81-
- "11"
82-
- "12"
83-
- "13"
8480
env:
8581
TIMING: 1
8682
runs-on: ubuntu-latest

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"npm-package-json-lint": "^7.1.0",
9292
"npm-run-all2": "^6.1.1",
9393
"outdent": "^0.8.0",
94+
"pretty-ms": "^8.0.0",
9495
"typescript": "^5.3.3",
9596
"vue-eslint-parser": "^9.3.2",
9697
"xo": "^0.56.0",

test/integration/projects.mjs

Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -126,37 +126,43 @@ export default [
126126
// #1075
127127
'https://github.com/jaredLunde/masonic',
128128
],
129-
// 'https://github.com/eslint/eslint',
130-
{
131-
repository: 'https://github.com/angular/angular',
132-
ignore: [
133-
'aio/content/examples/animations/src/app/open-close.component.3.ts',
134-
'aio/content/examples/router/src/app/app-routing.module.9.ts',
135-
'aio/tools/transforms/templates/data-module.template.js',
136-
'aio/tools/transforms/authors-package/index.js', // This file use `package` keyword as variable
137-
'packages/compiler-cli/test/**',
138-
'tools/**',
139-
// TODO[@fisker]: Check why it can't be parsed
140-
'packages/forms/src/validators.ts',
141-
],
142-
},
143-
// OOM
144-
// {
145-
// repository: 'https://github.com/microsoft/typescript',
146-
// ignore: [
147-
// // These file use `'\033'`
148-
// 'build/**',
149-
// ],
150-
// },
151-
{
152-
repository: 'https://github.com/microsoft/vscode',
153-
ignore: [
154-
// This file use `'\033'`
155-
'build/**',
156-
],
157-
},
158-
'https://github.com/element-plus/element-plus',
159-
'https://github.com/tusen-ai/naive-ui',
129+
[
130+
{
131+
repository: 'https://github.com/eslint/eslint',
132+
ignore: [
133+
'tests/fixtures',
134+
'tests/performance',
135+
],
136+
},
137+
'https://github.com/element-plus/element-plus',
138+
'https://github.com/tusen-ai/naive-ui',
139+
{
140+
repository: 'https://github.com/chakra-ui/chakra-ui',
141+
ignore: [
142+
'scripts/create-package.js', // This file use `package` keyword as variable
143+
],
144+
},
145+
'https://github.com/mozilla/pdf.js',
146+
{
147+
repository: 'https://github.com/TheThingsNetwork/lorawan-stack',
148+
babelPlugins: ['decorators'],
149+
},
150+
'https://github.com/zloirock/core-js',
151+
{
152+
repository: 'https://github.com/rollup/rollup',
153+
ignore: [
154+
'test/**',
155+
'scripts/perf.js',
156+
],
157+
},
158+
{
159+
repository: 'https://github.com/rust-lang/crates.io',
160+
ignore: [],
161+
babelPlugins: [
162+
['decorators', {decoratorsBeforeExport: true}],
163+
],
164+
},
165+
],
160166
{
161167
repository: 'https://github.com/gatsbyjs/gatsby',
162168
ignore: [
@@ -173,13 +179,8 @@ export default [
173179
'test/integration/**',
174180
],
175181
},
176-
{
177-
repository: 'https://github.com/chakra-ui/chakra-ui',
178-
ignore: [
179-
'scripts/create-package.js', // This file use `package` keyword as variable
180-
],
181-
},
182-
'https://github.com/mozilla/pdf.js',
182+
// #903
183+
'https://github.com/mattermost/mattermost-webapp',
183184
// #912
184185
{
185186
repository: 'https://github.com/microsoft/fluentui',
@@ -192,26 +193,32 @@ export default [
192193
'scripts/cypress.js',
193194
],
194195
},
195-
// #903
196-
'https://github.com/mattermost/mattermost-webapp',
197-
// These two project use `decorator`, try to enable when we use `@babel/eslint-parser`
198-
// 'https://github.com/untitled-labs/metabase-custom',
199-
// 'https://github.com/TheThingsNetwork/lorawan-stack',
200-
[
201-
'https://github.com/zloirock/core-js',
202-
{
203-
repository: 'https://github.com/rollup/rollup',
204-
ignore: [
205-
'test/**',
206-
'scripts/perf.js',
207-
],
208-
},
209-
],
210196
{
211-
repository: 'https://github.com/rust-lang/crates.io',
212-
ignore: [],
213-
babelPlugins: [
214-
['decorators', {decoratorsBeforeExport: true}],
197+
repository: 'https://github.com/angular/angular',
198+
ignore: [
199+
'aio/content/examples/animations/src/app/open-close.component.3.ts',
200+
'aio/content/examples/router/src/app/app-routing.module.9.ts',
201+
'aio/tools/transforms/templates/data-module.template.js',
202+
'aio/tools/transforms/authors-package/index.js', // This file use `package` keyword as variable
203+
'packages/compiler-cli/test/**',
204+
'tools/**',
205+
// TODO[@fisker]: Check why it can't be parsed
206+
'packages/forms/src/validators.ts',
207+
],
208+
},
209+
{
210+
repository: 'https://github.com/microsoft/typescript',
211+
ignore: [
212+
// Cannot parse `'\033'`
213+
'build/**',
214+
'tests/**',
215+
],
216+
},
217+
{
218+
repository: 'https://github.com/microsoft/vscode',
219+
ignore: [
220+
// Cannot parse `'\033'`
221+
'build/**',
215222
],
216223
},
217224
].flatMap((projectOrProjects, index) =>

test/integration/run-eslint.mjs

Lines changed: 69 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import process from 'node:process';
14
import {codeFrameColumns} from '@babel/code-frame';
2-
import {ESLint} from 'eslint';
5+
import eslintExperimentalApis from 'eslint/use-at-your-own-risk';
36
import chalk from 'chalk';
47
import {outdent} from 'outdent';
8+
import babelParser from '@babel/eslint-parser';
9+
import typescriptParser from '@typescript-eslint/parser';
10+
import vueParser from 'vue-eslint-parser';
11+
import prettyMilliseconds from 'pretty-ms';
512
import eslintPluginUnicorn from '../../index.js';
613

14+
const {FlatESLint} = eslintExperimentalApis;
15+
716
class UnicornIntegrationTestError extends AggregateError {
817
name = 'UnicornIntegrationTestError';
918

@@ -42,18 +51,44 @@ class UnicornEslintFatalError extends SyntaxError {
4251
const sum = (collection, fieldName) =>
4352
collection.reduce((total, {[fieldName]: value}) => total + value, 0);
4453

45-
async function runEslint(project) {
46-
const eslint = new ESLint({
47-
cwd: project.location,
48-
baseConfig: eslintPluginUnicorn.configs.all,
49-
useEslintrc: false,
50-
extensions: ['.js', '.mjs', '.cjs', '.ts', '.mts', '.cts', '.jsx', '.tsx', '.vue'],
51-
plugins: {
52-
unicorn: eslintPluginUnicorn,
54+
const patterns = ['js', 'mjs', 'cjs', 'ts', 'mts', 'cts', 'jsx', 'tsx', 'vue'].map(extension => `**/*.${extension}`);
55+
const basicConfigs = [
56+
eslintPluginUnicorn.configs['flat/all'],
57+
{
58+
rules: {
59+
// This rule crashing on replace string inside `jsx` or `Unicode escape sequence`
60+
'unicorn/string-content': 'off',
5361
},
54-
fix: true,
55-
overrideConfig: {
56-
parser: '@babel/eslint-parser',
62+
},
63+
{
64+
files: ['**/*.ts', '**/*.mts', '**/*.cts', '**/*.tsx'],
65+
languageOptions: {
66+
parser: typescriptParser,
67+
parserOptions: {
68+
project: [],
69+
},
70+
},
71+
},
72+
{
73+
files: ['**/*.vue'],
74+
languageOptions: {
75+
parser: vueParser,
76+
parserOptions: {
77+
parser: '@typescript-eslint/parser',
78+
ecmaFeatures: {
79+
jsx: true,
80+
},
81+
project: [],
82+
},
83+
},
84+
},
85+
];
86+
87+
function getBabelParserConfig(project) {
88+
return {
89+
languageOptions: {
90+
sourceType: 'module',
91+
parser: babelParser,
5792
parserOptions: {
5893
requireConfigFile: false,
5994
babelOptions: {
@@ -69,35 +104,30 @@ async function runEslint(project) {
69104
},
70105
},
71106
},
72-
ignorePatterns: project.ignore,
73-
rules: {
74-
// This rule crashing on replace string inside `jsx` or `Unicode escape sequence`
75-
'unicorn/string-content': 'off',
76-
},
77-
overrides: [
78-
{
79-
files: ['*.ts', '*.mts', '*.cts', '*.tsx'],
80-
parser: '@typescript-eslint/parser',
81-
parserOptions: {
82-
project: [],
83-
},
84-
},
85-
{
86-
files: ['*.vue'],
87-
parser: 'vue-eslint-parser',
88-
parserOptions: {
89-
parser: '@typescript-eslint/parser',
90-
ecmaFeatures: {
91-
jsx: true,
92-
},
93-
project: [],
94-
},
95-
},
96-
],
97107
},
108+
};
109+
}
110+
111+
async function runEslint(project) {
112+
const eslintIgnoreFile = path.join(project.location, '.eslintignore');
113+
const ignore = fs.existsSync(eslintIgnoreFile)
114+
? fs.readFileSync(eslintIgnoreFile, 'utf8').split('\n').filter(line => line && !line.startsWith('#'))
115+
: [];
116+
117+
const eslint = new FlatESLint({
118+
cwd: project.location,
119+
overrideConfigFile: true,
120+
overrideConfig: [
121+
getBabelParserConfig(project),
122+
...basicConfigs,
123+
{ignores: [...ignore, ...project.ignore]},
124+
],
125+
fix: true,
126+
errorOnUnmatchedPattern: false,
98127
});
99128

100-
const results = await eslint.lintFiles('.');
129+
const startTime = process.hrtime.bigint();
130+
const results = await eslint.lintFiles(patterns);
101131

102132
const errors = results
103133
.filter(file => file.fatalErrorCount > 0)
@@ -122,6 +152,7 @@ async function runEslint(project) {
122152
- warning: ${chalk.gray(warningCount)}
123153
- fixable error: ${chalk.gray(fixableErrorCount)}
124154
- fixable warning: ${chalk.gray(fixableWarningCount)}
155+
- duration: ${chalk.gray(prettyMilliseconds(Number((process.hrtime.bigint() - startTime) / 1_000_000n)))}
125156
`);
126157
}
127158

0 commit comments

Comments
 (0)