Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: configure biome linter #616

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

Merged
merged 8 commits into from
Nov 8, 2024

Conversation

maxmorozoff
Copy link
Contributor

@maxmorozoff maxmorozoff commented Nov 4, 2024

This PR migrates project’s linting configuration from ESLint to Biome.
See: #538

Changes

  • Migrated configuration
  • Updated CI Action

Performance improvements:

With Biome, linting the project now takes only 45ms on my machine.

Known Issues

Not all ESLint rules have direct equivalents in Biome as noted in Biome's documentation.

@khuezy
Copy link
Contributor

khuezy commented Nov 4, 2024

Thanks for the PR! I'm not familiar w/ biome so I'll defer to @conico974 and @vicb

@vicb
Copy link
Contributor

vicb commented Nov 4, 2024

I'll defer to @conico974 as he created the linked cleanup issue.

I usually agree with "if it ain't broken don't fix it" - especially when it comes to JS "build" tooling.

Copy link

pkg-pr-new bot commented Nov 4, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/@opennextjs/aws@616

commit: f1ed15d

@conico974
Copy link
Contributor

I usually agree with "if it ain't broken don't fix it" - especially when it comes to JS "build" tooling.

I kind of agree with that, but biome is so fast and it's a single deps that i think it may be worth it.

Unless there is a good reason to not merge this i think we should do it. I'll test that everything is working correctly tomorrow

@khuezy
Copy link
Contributor

khuezy commented Nov 4, 2024

@maxmorozoff
With Biome, linting the project now takes only 45ms on my machine.
How long did it take eslint?

@maxmorozoff
Copy link
Contributor Author

@maxmorozoff
With Biome, linting the project now takes only 45ms on my machine.
How long did it take eslint?

Around 40 seconds.
However, ESLint had more rules and plugins enabled.

You could consider enabling additional rules in Biome for a closer comparison.

As a temporary solution, we could run ESLint after Biome. This would have minimal impact on performance while allowing for a more gradual adoption, as it may require more fixes across the codebase.

@vicb
Copy link
Contributor

vicb commented Nov 5, 2024

I usually agree with "if it ain't broken don't fix it"

On the other hand, TS update is blocked by the current eslint config:

=============

WARNING: You are currently running a version of TypeScript which is not officially supported by @typescript-eslint/typescript-estree.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: >=4.3.5 <5.4.0

YOUR TYPESCRIPT VERSION: 5.6.3

Please only submit bug reports when using the officially supported version.

=============

Switching to biome could fix that so that we can update TS - which would allow some code simplification, as newer TS have improved type inference

Copy link
Contributor

@conico974 conico974 left a comment

Choose a reason for hiding this comment

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

There is some missing stuff here.

And we probably want to either switch to recommended: true (and probably disable some rules that we don't need) or add more rules.

I don't think using eslint for other missing rule is a good idea, we either fully switch to biome or stick with eslint. There is no point in running multiple linters

biome.json Outdated
"packages/open-next/src/minimize-js.ts"
]
},
"formatter": { "enabled": false },
Copy link
Contributor

Choose a reason for hiding this comment

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

We do want to run the formatter, it was done by the prettier eslint plugin before

biome.json Outdated
"**/pnpm-lock.yaml",
"**/dist/**",
"**/out/**",
"packages/open-next/assets/sharp-node-modules",
Copy link
Contributor

Choose a reason for hiding this comment

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

Not needed anymore

biome.json Outdated
"**/dist/**",
"**/out/**",
"packages/open-next/assets/sharp-node-modules",
"packages/open-next/src/minimize-js.ts"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you add this file ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The minimize-js.ts has an eslint-disable comment. In Biome to ignore this file, it should be configured in biome.json (docs)

Other paths could be removed.

biome.json Outdated
]
},
"formatter": { "enabled": false },
"organizeImports": { "enabled": false },
Copy link
Contributor

Choose a reason for hiding this comment

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

We want that enabled as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we configure formatting in biome.json or within a .editorconfig?

biome.json Outdated
@@ -0,0 +1,57 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
Copy link
Contributor

Choose a reason for hiding this comment

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

We want this to be enabled and use the ignore files, otherwise it will try to lint a lot of useless files

@maxmorozoff
Copy link
Contributor Author

switch to recommended: true

Biome summary:

Rule Name                                                    Diagnostics
  
  lint/complexity/noExcessiveCognitiveComplexity               1 (0 error(s), 1 warning(s), 0 info(s))
  lint/correctness/useExhaustiveDependencies                   1 (1 error(s), 0 warning(s), 0 info(s))
  lint/correctness/noUnnecessaryContinue                       1 (1 error(s), 0 warning(s), 0 info(s))
  lint/performance/noAccumulatingSpread                        13 (13 error(s), 0 warning(s), 0 info(s))
  lint/correctness/useJsxKeyInIterable                         14 (14 error(s), 0 warning(s), 0 info(s))
  lint/complexity/noUselessSwitchCase                          5 (5 error(s), 0 warning(s), 0 info(s))
  lint/style/noUnusedTemplateLiteral                           85 (72 error(s), 13 warning(s), 0 info(s))
  lint/style/useSelfClosingElements                            6 (6 error(s), 0 warning(s), 0 info(s))
  lint/suspicious/noImplicitAnyLet                             10 (10 error(s), 0 warning(s), 0 info(s))
  lint/suspicious/noArrayIndexKey                              2 (2 error(s), 0 warning(s), 0 info(s))
  lint/complexity/useLiteralKeys                               21 (21 error(s), 0 warning(s), 0 info(s))
  lint/style/useNumberNamespace                                16 (16 error(s), 0 warning(s), 0 info(s))
  lint/style/noInferrableTypes                                 14 (14 error(s), 0 warning(s), 0 info(s))
  lint/suspicious/noRedeclare                                  4 (4 error(s), 0 warning(s), 0 info(s))
  lint/style/noCommaOperator                                   2 (2 error(s), 0 warning(s), 0 info(s))
  lint/complexity/noForEach                                    37 (37 error(s), 0 warning(s), 0 info(s))
  lint/a11y/useIframeTitle                                     51 (51 error(s), 0 warning(s), 0 info(s))
  lint/a11y/useButtonType                                      6 (0 error(s), 6 warning(s), 0 info(s))
  lint/style/useTemplate                                       9 (9 error(s), 0 warning(s), 0 info(s))
  lint/a11y/useAltText                                         1 (1 error(s), 0 warning(s), 0 info(s))
  lint/style/useConst                                          21 (21 error(s), 0 warning(s), 0 info(s))
  lint/style/noVar                                             18 (18 error(s), 0 warning(s), 0 info(s))

Checked 299 files in 100ms. No fixes applied.
Found 318 errors.
Found 20 warnings.

After lint:fix:

Checked 299 files in 190ms. Fixed 24 files.
Found 268 errors.
Found 19 warnings.

Which rules would you like to keep?

Copy link

changeset-bot bot commented Nov 5, 2024

⚠️ No Changeset found

Latest commit: f1ed15d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@maxmorozoff
Copy link
Contributor Author

maxmorozoff commented Nov 5, 2024

The current configuration lints the project with no errors but generates 2,091 warnings. Some rules have automated, safe fixes that could be applied to the codebase, while others have unsafe fixes.

Steps involved

Enabled all rules

{
  "linter": {
    "enabled": true,
    "rules": {
      "all": true
    }
  },
}

Saved lint report to json and extracted rule names with a script

Encountered some issues with the --reporter=json option, as it's experimental. I used yq as a workaround.

// $ pnpm lint --diagnostic-level=error --reporter=junit | yq -p=xml -o=json > report.json

import report from "./report.json";

const errors = report.testsuites.testsuite.filter(
  (testcase) =>
    testcase["+@errors"] &&
    testcase.testcase["+@name"].startsWith("org.biome.lint"),
);
const rulesSet = new Set(errors.map((testcase) => testcase.testcase["+@name"]));
const config = {};
rulesSet.forEach((rule) => {
  const [, , , pkg, name] = rule.split(".");
  config[pkg] = {
    all: true,
    ...config[pkg],
    [name]: "warn",
  };
});

console.log(JSON.stringify(config, null, 2));

@conico974
Copy link
Contributor

@maxmorozoff We don't want to enable all rule, that's for sure.
For the recommended one we can remove:

  • everything a11y related (as these probably only happens for the e2e test)
  • I'd remove the noForEach as well

The rest is probably fine, and we can apply the safe one in this PR.
For the unsafe one, we may have to look one by one and fix them in subsequent PR. As of now we can set them as warning and fix them later. We may want to add some other rule as well, but again in future PR

@maxmorozoff
Copy link
Contributor Author

@conico974, the default value for recommended is true, so I've omitted it. Accessibility errors occurred in the examples/ directory. Should I disable these rules globally, or should we keep the recommended rules?
Also, should I update .vscode/settings.json and add .vscode/extensions.json?
Should I add the commit with fixes in .git-blame-ignore-revs?

@conico974
Copy link
Contributor

@maxmorozoff

Should I disable these rules globally, or should we keep the recommended rules?

Disable them, examples only contains e2e, we don't care that much about having perfect app there

Also, should I update .vscode/settings.json and add .vscode/extensions.json?
Should I add the commit with fixes in .git-blame-ignore-revs?

Good idea for both questions, go ahead

@maxmorozoff
Copy link
Contributor Author

@conico974, could you please review the latest commits and let me know if they look good to you? Any additional feedback is also welcome!

Thank you!

@khuezy
Copy link
Contributor

khuezy commented Nov 7, 2024

What do you think of adding --diagnostic-level=error. When I try biome lint it includes a bunch of warns

I'm playing around w/ biome and it's really fast!

@conico974
Copy link
Contributor

What do you think of adding --diagnostic-level=error. When I try biome lint it includes a bunch of warns

My advice is that we should fix those warning (or disable them if we feel they're useless) just not in this PR, i just want to avoid a 300 files changed PR where it would be way too easy to miss something that might break something (especially with the eslint plugin we have that can replace code)

I'm playing around w/ biome and it's really fast!

Yeah i've tested it a bit and it's so fast, it seems almost unreal 😆. There is a bunch of new javascript tooling around lately that are insane speed wise (like the oxc project)

Copy link
Contributor

@conico974 conico974 left a comment

Choose a reason for hiding this comment

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

I just have 2 question here, but if everything is fine we should merge this
As for what's need to be done next, we need to either ignore or fix the lint rule, in this order : suspicious, correctness, performance, complexity and lastly style.
When all of this is done we'll need to think if we want to add other rule

},
"style": {
"noUnusedTemplateLiteral": "warn",
"noInferrableTypes": "warn", // safe fix
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you apply these safe fixes ? If so no need to set them as warn, we want to avoid them as much as possible so an error is fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've only applied the fixes that were causing formatting or import order errors, which I forgot to mention. Now, running pnpm lint exits with 0, while pnpm lint:fix would apply additional linting fixes. It might be better to address these in the next PR, as they are more nuanced and might not be necessary if some rules are disabled.

@vicb
Copy link
Contributor

vicb commented Nov 8, 2024

great work on this PR!

I read "like the oxc project" and I'm puzzled by how the JS world like to fuel the confusion... biome use to be rome and oxc is now void0 🤷

@conico974
Copy link
Contributor

biome use to be rome and oxc is now void0

And biome use oxc under the hood and oxc also have a linter 🤯

Copy link
Contributor

@conico974 conico974 left a comment

Choose a reason for hiding this comment

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

LGTM Thanks a lot for this

@conico974 conico974 merged commit 04379e2 into opennextjs:main Nov 8, 2024
3 checks passed
@maxmorozoff
Copy link
Contributor Author

@conico974 Thank you! Would you like me to open the next PR to address the linting warnings, or do you plan to handle it later? Happy to help!

@conico974
Copy link
Contributor

@maxmorozoff i'd be happy if you open them yeah

@conico974
Copy link
Contributor

Maybe i spoke too soon, looks like @vicb is already taking care of a bunch of them

@vicb
Copy link
Contributor

vicb commented Nov 8, 2024

#627 should conflict with #626 and I don't think I'll have time to work on the PR before Tuesday, so up to you.

@sommeeeer
Copy link
Contributor

Good job @maxmorozoff and everyone else on this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants