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(linter): implement useImportExtensions #2725
base: main
Are you sure you want to change the base?
Conversation
CodSpeed Performance ReportMerging #2725 will not alter performanceComparing Summary
|
Should we disable this rule for typescript files? For a typical typescript projects, adding files extensions is usually handled by the bundler, and typescript doesn't even allow imported files to end with |
@vohoanglong0107 As of typescript 5.0 you can use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice rule!
Just a performance nit.
crates/biome_js_analyze/src/lint/nursery/use_import_extensions.rs
Outdated
Show resolved
Hide resolved
4d7cf90
to
a456967
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall it looks good. There are few missing cases, and left few suggestions to avoid allocations
crates/biome_js_analyze/src/lint/nursery/use_import_extensions.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_import_extensions.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_import_extensions.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_import_extensions.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_import_extensions.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_import_extensions.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_import_extensions.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_import_extensions.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rule doesn't cover import("./file.js")
and require("./file.js")
. @minht11, do you plan to add it to this PR or a following PR?
47f9eba
to
3bbc149
Compare
crates/biome_js_analyze/src/lint/nursery/use_import_extensions.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_import_extensions.rs
Outdated
Show resolved
Hide resolved
4bd8041
to
6bd1b03
Compare
Once the conflicts resolved, I think we can merge this PR. |
@Conaclos what about windows tests? Right now they fail, because on windows os paths us different slash. Should I replace pathBuf with vector or something like that? |
We shouldn't rely on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to block it until we fix Windows test cases.
We should compose the new import specifier manually instead of using PathBuf
.
Ah, I've also run into that at some point. Maybe we should add it to the contributing guide somewhere. |
I replaced path_buf with string concatenation, windows test now pass. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation doesn't mention whether it supports import()
and require()
or not, we should add that
use crate::JsRuleAction; | ||
|
||
declare_rule! { | ||
/// Require import extensions for relative imports. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Require import extensions for relative imports. | |
/// Enforce file extensions for relative imports. |
/// Require import extensions for relative imports. | ||
/// | ||
/// Browsers and Node.js do not natively support importing files without extensions. This rule | ||
/// enforces the use of import extensions for relative imports to make the code more consistent. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// enforces the use of import extensions for relative imports to make the code more consistent. | |
/// enforces the use of file extensions for relative imports to make the code more consistent. |
/// Browsers and Node.js do not natively support importing files without extensions. This rule | ||
/// enforces the use of import extensions for relative imports to make the code more consistent. | ||
/// | ||
/// Tooling also benefits from explicit import extensions, because they do not need to guess which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Tooling also benefits from explicit import extensions, because they do not need to guess which | |
/// Tooling also benefits from explicit file extensions, because they do not need to guess which |
Summary
Closes #2674
Implements import/extensions requirement for relative extensions.
Rule suggests unsafe fix based on current file and import path, given the limitations of not being able to access file system.
Test Plan
Added snapshots