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(editorconfig): reenable editorconfig support, add cli flag to disable it #3246

Conversation

dyc3
Copy link
Contributor

@dyc3 dyc3 commented Jun 20, 2024

Summary

This PR reenables editorconfig support, and additionally adds a cli flag, --use-editorconfig, to control whether or not it's enabled.

related to: #1724

Test Plan

I've reenabled the unit tests that I wrote for this.

@github-actions github-actions bot added the A-CLI Area: CLI label Jun 20, 2024
@dyc3 dyc3 force-pushed the 06-15-feat_editorconfig_reenable_editorconfig_support branch from f572723 to 0e41227 Compare June 20, 2024 19:08
@dyc3 dyc3 marked this pull request as ready for review June 20, 2024 19:33
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

In our repository, we have command called pnpm check that runs the Biome CLI in dev mode. If you run, you'll notice that it will break:

configuration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ Couldn't parse the **.yml, reason: recursive wildcards must form a single path component
  

 ELIFECYCLE  Command failed with exit code 1.

We should fix that

@ematipico
Copy link
Member

ematipico commented Jun 21, 2024

After fixing the issue with editor config **.yml -> *.yml (we should make the error message a bit simpler to understand...), I run into overriding issues.. meaning that now tsconfig.json is failing because it isn't parsed as JSONC anymore:

~/packages/@biomejs/js-api/tsconfig.json:3:24 parse ━━━━━━━━━━━━━━━━━━━━━━━

  ✖ JSON standard does not allow comments.
  
    1 │ {
    2 │   "compilerOptions": {
  > 3 │     "target": "es2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
      │                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    4 │     "module": "commonjs" /* Specify what module code is generated. */,
    5 │     "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
  

tsconfig.json, like other files, are "well known", meaning that are always parsed as JSONC files

@dyc3 dyc3 force-pushed the 06-15-feat_editorconfig_reenable_editorconfig_support branch from 0e41227 to e636d2f Compare June 21, 2024 15:20
@github-actions github-actions bot added the A-Project Area: project label Jun 21, 2024
@dyc3
Copy link
Contributor Author

dyc3 commented Jun 21, 2024

I've updated it so that error will now be printed as:

/home/<absolute path>/.editorconfig configuration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ Couldn't parse the pattern "**.yml". Reason: Pattern syntax error near position 2: recursive wildcards must form a single path component

and it'll now convert that pattern into one biome can use. That tsconfig.json thing sounds like it's out of scope for editorconfig support?

@dyc3 dyc3 requested a review from ematipico June 21, 2024 15:34
@dyc3 dyc3 force-pushed the 06-15-feat_editorconfig_reenable_editorconfig_support branch from e636d2f to fd8688d Compare June 21, 2024 15:54
@ematipico
Copy link
Member

That tsconfig.json thing sounds like it's out of scope for editorconfig support?

But it's a regression I am experiencing in this PR. The command pnpm check doesn't work anymore. Is it expected?

@dyc3
Copy link
Contributor Author

dyc3 commented Jun 21, 2024

I think this is a bug on main. Adding the following override to this repo's biome.json produces the same result.

"overrides": [
    {
      "include": ["**/*.json"],
      "formatter": {
        "indentStyle": "space"
      }
    }
  ]

Obviously, we can't merge this without that being resolved. I'll look into it.

@dyc3
Copy link
Contributor Author

dyc3 commented Jun 21, 2024

Running cargo run --bin biome -- check packages/@biomejs/backend-jsonrpc/tsconfig.json with the override does not produce the diagnostics. I think the source of the problem has something to do with the caching being done here:

if let Ok(readonly_cache) = self.cached_json_parser_options.read() {
if let Some(cached_options) = readonly_cache.as_ref() {
*options = *cached_options;
return;
}
}

@dyc3
Copy link
Contributor Author

dyc3 commented Jun 22, 2024

@ematipico I've submitted a draft PR to fix this in #3260, but I don't really like the solution. Details are in the PR.

@dyc3 dyc3 force-pushed the 06-15-feat_editorconfig_reenable_editorconfig_support branch from fd8688d to f453783 Compare June 26, 2024 13:32
@dyc3
Copy link
Contributor Author

dyc3 commented Jun 26, 2024

@ematipico This PR should be unblocked now.

I went ahead and disabled the caching for json overrides because the behavior was incorrect, as discussed in #3260, despite the potential for performance regressions. pnpm check does throw a diagnostic that wasn't there before, but its not a regression from main.

crates/biome_service/src/settings.rs Show resolved Hide resolved
crates/biome_service/src/configuration.rs Outdated Show resolved Hide resolved
crates/biome_cli/src/cli_options.rs Outdated Show resolved Hide resolved
@dyc3 dyc3 force-pushed the 06-15-feat_editorconfig_reenable_editorconfig_support branch 3 times, most recently from 2e6b8d5 to cd71fd0 Compare June 27, 2024 11:09
@dyc3 dyc3 requested a review from ematipico June 27, 2024 11:21
@dyc3 dyc3 force-pushed the 06-15-feat_editorconfig_reenable_editorconfig_support branch 5 times, most recently from cb83bbe to c804f00 Compare June 30, 2024 11:12
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

This looks good to me. I am a bit worried about the default, and I would like to know what you think. Once settled on the default value, we can merge it :) Great work @dyc3, thank you for landing this feature

@@ -98,6 +103,7 @@ impl Default for FormatterConfiguration {
bracket_spacing: Default::default(),
ignore: Default::default(),
include: Default::default(),
use_editorconfig: true,
Copy link
Member

Choose a reason for hiding this comment

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

I am a bit worried about this default. It makes sense to have to true, however this could break some formatting for users that already use Biome and have an .editorconfig somewhere. What do you think? Should we set it false for now, and set it to true for v2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be the most conservative. On the other hand, prettier enables editorconfig support by default, and keeping this behavior when migrating from prettier would be a better user experience.

I think we should set this to false by default, but when migrating from prettier, set it to true if it's unspecified.

ref: https://prettier.io/docs/en/configuration.html#editorconfig

Copy link
Contributor Author

@dyc3 dyc3 Jul 1, 2024

Choose a reason for hiding this comment

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

actually it turns out that prettier's options.editorconfig doesn't work at all, see: prettier/prettier#15255

So we should always turn it on when migrating

Copy link
Member

@ematipico ematipico Jul 1, 2024

Choose a reason for hiding this comment

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

Yeah, sounds goods me!

crates/biome_configuration/src/formatter.rs Outdated Show resolved Hide resolved
@dyc3 dyc3 force-pushed the 06-15-feat_editorconfig_reenable_editorconfig_support branch from c804f00 to 540d90a Compare July 1, 2024 12:10
@dyc3 dyc3 requested a review from ematipico July 1, 2024 12:12
@dyc3 dyc3 force-pushed the 06-15-feat_editorconfig_reenable_editorconfig_support branch from 540d90a to 8573a71 Compare July 1, 2024 12:21
@dyc3 dyc3 force-pushed the 06-15-feat_editorconfig_reenable_editorconfig_support branch from 8573a71 to f7d7064 Compare July 1, 2024 12:29
@ematipico ematipico merged commit 8b54010 into biomejs:main Jul 1, 2024
10 checks passed
@dyc3 dyc3 deleted the 06-15-feat_editorconfig_reenable_editorconfig_support branch July 1, 2024 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Area: CLI A-Project Area: project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants