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

Add Experimental support of Flat Config #1522

Merged
merged 11 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

To remain consistent with the useESLintClass setting, I would remove the experimental suffix here.

Copy link
Contributor Author

@uhyo uhyo Oct 9, 2022

Choose a reason for hiding this comment

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

Sorry for confusing you, but I'd like to keep the name experimental because, unlike useESLintClass, this config will be unnecessary in the future when Flat Config is considered stable. At that time the regular ESLint class will have the Flat Config support as described here. Then this config can be removed and users can use Flat Config without additional configuration.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand now. Thanks for explaining!

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'),
Copy link
Contributor

Choose a reason for hiding this comment

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

You will also need to add this file to this filter:

const configFileFilter: DocumentFilter = { scheme: 'file', pattern: '**/.eslintr{c.js,c.yaml,c.yml,c,c.json}' };

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
59 changes: 33 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
"extensionKind": [
"workspace"
],
"enabledApiProposals": [
],
"enabledApiProposals": [],
"main": "./client/out/extension",
"capabilities": {
"virtualWorkspaces": {
Expand Down Expand Up @@ -182,6 +181,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)."
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned previously, I would remove the experimental here, since flat config will eventually become stable and we don't want to have separate settings for the experimental and stable APIs.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can dismiss this comment now that you've explained why we're using the experimental name :)

},
"eslint.workingDirectories": {
"scope": "resource",
"type": "array",
Expand Down Expand Up @@ -338,7 +343,8 @@
"items": {
"type": "string"
}
}, {
},
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Not too important, but unless you did this on purpose, you might have a formatter making changes here.

Copy link
Contributor Author

@uhyo uhyo Oct 9, 2022

Choose a reason for hiding this comment

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

Sorry, I reverted the formatting changes.

"type": "null"
}
],
Expand Down Expand Up @@ -425,7 +431,8 @@
"items": {
"type": "string"
}
}, {
},
{
"type": "null"
}
],
Expand Down Expand Up @@ -464,29 +471,29 @@
"description": "Override the severity of one or more rules reported by this extension, regardless of the project's ESLint config. Use globs to apply default severities for multiple rules."
},
"eslint.notebooks.rules.customizations": {
"items": {
"properties": {
"severity": {
"enum": [
"downgrade",
"error",
"info",
"default",
"upgrade",
"warn",
"off"
],
"type": "string"
},
"rule": {
"type": "string"
}
"items": {
"properties": {
"severity": {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the change here? Did you replace tabs with spaces?

"enum": [
"downgrade",
"error",
"info",
"default",
"upgrade",
"warn",
"off"
],
"type": "string"
},
"type": "object"
"rule": {
"type": "string"
}
},
"scope": "resource",
"type": "array",
"description": "A special rules customization section for text cells in notebook documents."
"type": "object"
},
"scope": "resource",
"type": "array",
"description": "A special rules customization section for text cells in notebook documents."
}
}
},
Expand Down Expand Up @@ -580,4 +587,4 @@
"webpack-cli": "^4.10.0",
"shelljs": "^0.8.5"
}
}
}
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