Skip to content

Commit

Permalink
Add Experimental support of Flat Config (#1522)
Browse files Browse the repository at this point in the history
* feat(client): add eslint.config.js to watch target

* add experimentalUseFlatConfig setting

* Support loading FlatESLint

* add flatConfig playground

* fix

* clean up flatConfig playground

* comment in

* revert unnecessary formatting changes

* fix type and make error message more helpful

* update error message

* improve error message
  • Loading branch information
uhyo authored Oct 24, 2022
1 parent 4b92c12 commit 5ae084e
Show file tree
Hide file tree
Showing 10 changed files with 2,341 additions and 26 deletions.
1 change: 1 addition & 0 deletions $shared/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export type ConfigurationSettings = {
validate: Validate;
packageManager: PackageManagers;
useESLintClass: boolean;
experimentalUseFlatConfig: boolean;
codeAction: CodeActionSettings;
codeActionOnSave: CodeActionsOnSaveSettings;
format: boolean;
Expand Down
4 changes: 3 additions & 1 deletion client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export namespace ESLintClient {

// Filters for client options
const packageJsonFilter: DocumentFilter = { scheme: 'file', pattern: '**/package.json' };
const configFileFilter: DocumentFilter = { scheme: 'file', pattern: '**/.eslintr{c.js,c.yaml,c.yml,c,c.json}' };
const configFileFilter: DocumentFilter = { scheme: 'file', pattern: '**/{.eslintr{c.js,c.yaml,c.yml,c,c.json},eslint.config.js}' };
const supportedQuickFixKinds: Set<string> = new Set([CodeActionKind.Source.value, CodeActionKind.SourceFixAll.value, `${CodeActionKind.SourceFixAll.value}.eslint`, CodeActionKind.QuickFix.value]);

// A map of documents synced to the server
Expand Down Expand Up @@ -394,6 +394,7 @@ export namespace ESLintClient {
synchronize: {
fileEvents: [
Workspace.createFileSystemWatcher('**/.eslintr{c.js,c.cjs,c.yaml,c.yml,c,c.json}'),
Workspace.createFileSystemWatcher('**/eslint.config.js'),
Workspace.createFileSystemWatcher('**/.eslintignore'),
Workspace.createFileSystemWatcher('**/package.json')
]
Expand Down Expand Up @@ -604,6 +605,7 @@ export namespace ESLintClient {
validate: Validate.off,
packageManager: config.get<PackageManagers>('packageManager', 'npm'),
useESLintClass: config.get<boolean>('useESLintClass', false),
experimentalUseFlatConfig: config.get<boolean>('experimentalUseFlatConfig', false),
codeActionOnSave: {
mode: CodeActionsOnSaveMode.all
},
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@
"default": false,
"description": "Since version 7 ESLint offers a new API call ESLint. Use it even if the old CLIEngine is available. From version 8 on forward on ESLint class is available."
},
"eslint.experimentalUseFlatConfig": {
"scope": "resource",
"type": "boolean",
"default": false,
"description": "Enable support of experimental Flat Config (aka eslint.config.js, supported by ESLint version 8.21 or later)."
},
"eslint.workingDirectories": {
"scope": "resource",
"type": "array",
Expand Down
22 changes: 22 additions & 0 deletions playgrounds/flatConfig/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Place your settings in this file to overwrite default and user settings.
{
"eslint.enable": true,
"eslint.run": "onType",
"eslint.trace.server": {
"verbosity": "messages",
"format": "text"
},
"files.autoSave": "off",
"editor.formatOnSave": false,
"[javascript]": {
"editor.formatOnSave": false,
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"eslint.format.enable": true,
"eslint.onIgnoredFiles": "off",
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.fixAll.eslint": true
},
"eslint.experimentalUseFlatConfig": true
}
12 changes: 12 additions & 0 deletions playgrounds/flatConfig/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function bar() {
if (foo) {
foo++;
}
}

function foo(x) {
console.log(x);
bar();
var x = 10;
console.log(undef);
}
26 changes: 26 additions & 0 deletions playgrounds/flatConfig/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const globals = require('globals');

module.exports = [
"eslint:recommended",
{
files: ["**/*.js"],
languageOptions: {
parserOptions: {
sourceType: "module"
},
globals: {
...globals.browser,
...globals.node,
...globals.es6,
...globals.commonjs
}
},
},
{
files: ["sub/*.js"],
rules: {
"no-undef": "warn",
"no-console": "warn"
}
}
]
Loading

0 comments on commit 5ae084e

Please sign in to comment.