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

fix: prepend eslint default configs #66

Merged
merged 3 commits into from
Jun 21, 2024
Merged
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
35 changes: 35 additions & 0 deletions src/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,41 @@ export async function readConfig(
if (!Array.isArray(rawConfigs))
rawConfigs = [rawConfigs]

// ESLint applies these default configs to all files
// https://github.com/eslint/eslint/blob/21d3766c3f4efd981d3cc294c2c82c8014815e6e/lib/config/default-config.js#L66-L69
rawConfigs.unshift(
{
name: 'eslint/defaults/languages',
languageOptions: {
sourceType: 'module',
ecmaVersion: 'latest',
parserOptions: {},
},
linterOptions: {
reportUnusedDisableDirectives: 1,
},
} as FlatConfigItem,
{
name: 'eslint/defaults/ignores',
ignores: [
'**/node_modules/',
'.git/',
],
} as FlatConfigItem,
Comment on lines +121 to +127
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove them from here then:

ignore: [
'**/node_modules/**',
'**/dist/**',
'**/.git/**',
...configs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antfu Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind either way - in the end this globbing things is more or less a approximation for reference. Would be nice if we could reuse the ESLint's logic to get the same result. Otherwise I see no much differences, and honestly would slightly prefer to keep it as-is to make sure we don't over scan.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antfu Added a request to expose the ESLint logic: eslint/eslint#18619

{
name: 'eslint/defaults/files',
files: ['**/*.js', '**/*.mjs'],
} as FlatConfigItem,
{
name: 'eslint/defaults/files-cjs',
files: ['**/*.cjs'],
languageOptions: {
sourceType: 'commonjs',
ecmaVersion: 'latest',
},
} as FlatConfigItem,
)

const rulesMap = new Map<string, RuleInfo>()

// Try resolve `eslint` module from the same directory as the config file
Expand Down
Loading