Skip to content

Commit 9a5855e

Browse files
Netailautofix-ci[bot]ematipico
authored
feat: noRestrictedDependencies (#10467)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
1 parent 03274b9 commit 9a5855e

39 files changed

Lines changed: 1604 additions & 127 deletions

File tree

.changeset/modern-lands-find.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Added a new nursery rule [`noRestrictedDependencies`](https://biomejs.dev/linter/rules/no-restricted-dependencies/), which flags imports and `package.json` dependency entries that have better alternatives in e18e's module replacement data.
6+
7+
For example, the package `globby` is reported because there's a better alternative:
8+
9+
```js
10+
import glob from "globby"
11+
```
12+
13+
```json
14+
{
15+
"dependencies": {
16+
"globby": "x.x.x"
17+
}
18+
}
19+
```

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
/crates/biome_css_analyze/src/{lint,assist,syntax}/*.rs linguist-generated=true text=auto eol=lf
2020
/crates/biome_css_analyze/src/options.rs linguist-generated=true text=auto eol=lf
2121
/crates/biome_css_analyze/src/registry.rs linguist-generated=true text=auto eol=lf
22+
/crates/biome_css_analyze/src/baseline_data.rs linguist-generated=true text=auto eol=lf
2223
# JSON
2324
/crates/biome_json_formatter/src/json/any/*.rs linguist-generated=true text=auto eol=lf
2425
/crates/biome_json_analyze/src/{lint,assist,syntax}.rs linguist-generated=true text=auto eol=lf

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ biome_markdown_syntax = { path = "./crates/biome_markdown_syntax", versio
8383
biome_markup = { path = "./crates/biome_markup", version = "0.5.7" }
8484
biome_migrate = { path = "./crates/biome_migrate" }
8585
biome_module_graph = { path = "./crates/biome_module_graph", version = "0.0.1" }
86+
biome_module_replacements = { path = "./crates/biome_module_replacements", version = "0.5.7" }
8687
biome_package = { path = "./crates/biome_package", version = "0.5.7" }
8788
biome_parser = { path = "./crates/biome_parser", version = "0.5.7" }
8889
biome_plugin_loader = { path = "./crates/biome_plugin_loader", version = "0.0.1" }

crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_configuration/src/analyzer/linter/rules.rs

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_configuration/src/generated/linter_options_check.rs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_diagnostics_categories/src/categories.rs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_js_analyze/Cargo.toml

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,45 @@ harness = false
2020
name = "use_sorted_classes_parser"
2121

2222
[dependencies]
23-
biome_analyze = { workspace = true }
24-
biome_analyze_macros = { workspace = true }
25-
biome_aria = { workspace = true }
26-
biome_aria_metadata = { workspace = true }
27-
biome_console = { workspace = true }
28-
biome_control_flow = { workspace = true }
29-
biome_deserialize = { workspace = true, features = ["smallvec"] }
30-
biome_deserialize_macros = { workspace = true }
31-
biome_diagnostics = { workspace = true }
32-
biome_fs = { workspace = true }
33-
biome_glob = { workspace = true, features = ["biome_deserialize", "serde"] }
34-
biome_js_factory = { workspace = true }
35-
biome_js_semantic = { workspace = true }
36-
biome_js_syntax = { workspace = true }
37-
biome_js_type_info = { workspace = true }
38-
biome_jsdoc_comment = { workspace = true }
39-
biome_module_graph = { workspace = true }
40-
biome_package = { workspace = true }
41-
biome_project_layout = { workspace = true }
42-
biome_resolver = { workspace = true }
43-
biome_rowan = { workspace = true }
44-
biome_rule_options = { workspace = true }
45-
biome_string_case = { workspace = true, features = ["biome_rowan"] }
46-
biome_suppression = { workspace = true }
47-
biome_tailwind_parser = { workspace = true }
48-
biome_tailwind_syntax = { workspace = true }
49-
biome_unicode_table = { workspace = true }
50-
bitvec = "1.0.1"
51-
camino = { workspace = true }
52-
enumflags2 = { workspace = true }
53-
globset = { workspace = true }
54-
phf = { workspace = true }
55-
regex = { workspace = true }
56-
roaring = "0.11.3"
57-
rustc-hash = { workspace = true }
58-
schemars = { workspace = true, optional = true }
59-
serde = { workspace = true, features = ["derive"] }
60-
smallvec = { workspace = true }
23+
biome_analyze = { workspace = true }
24+
biome_analyze_macros = { workspace = true }
25+
biome_aria = { workspace = true }
26+
biome_aria_metadata = { workspace = true }
27+
biome_console = { workspace = true }
28+
biome_control_flow = { workspace = true }
29+
biome_deserialize = { workspace = true, features = ["smallvec"] }
30+
biome_deserialize_macros = { workspace = true }
31+
biome_diagnostics = { workspace = true }
32+
biome_fs = { workspace = true }
33+
biome_glob = { workspace = true, features = ["biome_deserialize", "serde"] }
34+
biome_js_factory = { workspace = true }
35+
biome_js_semantic = { workspace = true }
36+
biome_js_syntax = { workspace = true }
37+
biome_js_type_info = { workspace = true }
38+
biome_jsdoc_comment = { workspace = true }
39+
biome_module_graph = { workspace = true }
40+
biome_module_replacements = { workspace = true }
41+
biome_package = { workspace = true }
42+
biome_project_layout = { workspace = true }
43+
biome_resolver = { workspace = true }
44+
biome_rowan = { workspace = true }
45+
biome_rule_options = { workspace = true }
46+
biome_string_case = { workspace = true, features = ["biome_rowan"] }
47+
biome_suppression = { workspace = true }
48+
biome_tailwind_parser = { workspace = true }
49+
biome_tailwind_syntax = { workspace = true }
50+
biome_unicode_table = { workspace = true }
51+
bitvec = "1.0.1"
52+
camino = { workspace = true }
53+
enumflags2 = { workspace = true }
54+
globset = { workspace = true }
55+
phf = { workspace = true }
56+
regex = { workspace = true }
57+
roaring = "0.11.3"
58+
rustc-hash = { workspace = true }
59+
schemars = { workspace = true, optional = true }
60+
serde = { workspace = true, features = ["derive"] }
61+
smallvec = { workspace = true }
6162

6263
[dev-dependencies]
6364
biome_fs = { path = "../biome_fs" }

crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::services::manifest::Manifest;
1+
use crate::{services::manifest::Manifest, utils::parse_package_name};
22
use biome_analyze::{
33
Rule, RuleDiagnostic, RuleDomain, RuleSource, context::RuleContext, declare_lint_rule,
44
};
@@ -284,80 +284,9 @@ impl Rule for NoUndeclaredDependencies {
284284
}
285285
}
286286

287-
fn parse_package_name(path: &str) -> Option<&str> {
288-
let mut in_scope = false;
289-
for (i, c) in path.bytes().enumerate() {
290-
match c {
291-
b'@' if i == 0 => {
292-
in_scope = true;
293-
}
294-
// uppercase characters are not allowed in package name
295-
// Here we are more tolerant and accept them.
296-
b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' => {}
297-
b'.' if i != 0 => {}
298-
b'/' => {
299-
if in_scope {
300-
if i == 1 {
301-
// Invalid empty scope
302-
// `@/`
303-
return None;
304-
} else {
305-
// We consumed the scope.
306-
// `@scope/`
307-
in_scope = false;
308-
}
309-
} else if i == 0 {
310-
// absolute path
311-
return None;
312-
} else {
313-
// We consumed the package name
314-
return Some(&path[..i]);
315-
}
316-
}
317-
_ => {
318-
return None;
319-
}
320-
}
321-
}
322-
// Handle cases where only the scope is given. e.g. `@scope/`
323-
(!path.ends_with('/')).then_some(path)
324-
}
325-
326287
fn is_type_import(import: &AnyJsImportLike) -> bool {
327288
match import.parent::<AnyJsImportClause>() {
328289
Some(clause) => clause.type_token().is_some(),
329290
_ => false,
330291
}
331292
}
332-
333-
#[test]
334-
fn test() {
335-
assert_eq!(
336-
parse_package_name("@scope/package-name"),
337-
Some("@scope/package-name")
338-
);
339-
assert_eq!(
340-
parse_package_name("@scope/package-name/path"),
341-
Some("@scope/package-name")
342-
);
343-
assert_eq!(parse_package_name("package_"), Some("package_"));
344-
assert_eq!(parse_package_name("package/path"), Some("package"));
345-
assert_eq!(parse_package_name("0"), Some("0"));
346-
assert_eq!(parse_package_name("0/path"), Some("0"));
347-
assert_eq!(parse_package_name("-"), Some("-"));
348-
assert_eq!(parse_package_name("-/path"), Some("-"));
349-
assert_eq!(parse_package_name("a.js"), Some("a.js"));
350-
assert_eq!(parse_package_name("@././file"), Some("@./."));
351-
352-
// Invalid package names that we accept
353-
assert_eq!(parse_package_name("PACKAGE"), Some("PACKAGE"));
354-
assert_eq!(parse_package_name("_"), Some("_"));
355-
356-
// Invalid package names that we reject
357-
assert_eq!(parse_package_name("@/path"), None);
358-
assert_eq!(parse_package_name("."), None);
359-
assert_eq!(parse_package_name("./path"), None);
360-
assert_eq!(parse_package_name("#path"), None);
361-
assert_eq!(parse_package_name("/path"), None);
362-
assert_eq!(parse_package_name("p@ckage/name"), None);
363-
}

0 commit comments

Comments
 (0)