feat(rome_js_analyze): new rule `noRestrictedGlobals`
MODIFY
crates/rome_diagnostics_categories/src/categories.rs
crates/rome_diagnostics_categories/src/categories.rs
@@ -55,6 +55,7 @@ define_dategories! {
"lint/nursery/noAutofocus": "https://rome.tools/docs/lint/rules/noAutofocus",
"lint/nursery/useBlankTarget": "https://rome.tools/docs/lint/rules/useBlankTarget",
"lint/nursery/useValidAnchor": "https://rome.tools/docs/lint/rules/useValidAnchor",
+ "lint/nursery/noRestrictedGlobals": "https://rome.tools/docs/lint/rules/noRestrictedGlobals",
"lint/style/noNegationElse": "https://rome.tools/docs/lint/rules/noNegationElse",
"lint/style/noShoutyConstants": "https://rome.tools/docs/lint/rules/noShoutyConstants",
"lint/style/useSelfClosingElements": "https://rome.tools/docs/lint/rules/useSelfClosingElements",

MODIFY
crates/rome_js_analyze/src/lib.rs
crates/rome_js_analyze/src/lib.rs
@@ -119,7 +119,10 @@ mod tests {
#[ignore]
#[test]
fn quick_test() {
- const SOURCE: &str = r#"<a href='http://external.link' target='_blank'>child</a>
+ const SOURCE: &str = r#"function f(event, error) {
+ console.log(event);
+ console.log(error);
+}
"#;
let parsed = parse(SOURCE, FileId::zero(), SourceType::jsx());

MODIFY
crates/rome_js_analyze/src/semantic_analyzers/nursery.rs
crates/rome_js_analyze/src/semantic_analyzers/nursery.rs
@@ -6,6 +6,7 @@ mod no_children_prop;
mod no_dangerously_set_inner_html;
mod no_dangerously_set_inner_html_with_children;
mod no_render_return_value;
+mod no_restricted_globals;
mod no_undeclared_variables;
mod no_unused_variables;
mod no_useless_fragments;
@@ -13,4 +14,4 @@ mod no_void_elements_with_children;
mod use_button_type;
mod use_camel_case;
mod use_fragment_syntax;
-declare_group! { pub (crate) Nursery { name : "nursery" , rules : [self :: no_array_index_key :: NoArrayIndexKey , self :: no_children_prop :: NoChildrenProp , self :: no_dangerously_set_inner_html :: NoDangerouslySetInnerHtml , self :: no_dangerously_set_inner_html_with_children :: NoDangerouslySetInnerHtmlWithChildren , self :: no_render_return_value :: NoRenderReturnValue , self :: no_undeclared_variables :: NoUndeclaredVariables , self :: no_unused_variables :: NoUnusedVariables , self :: no_useless_fragments :: NoUselessFragments , self :: no_void_elements_with_children :: NoVoidElementsWithChildren , self :: use_button_type :: UseButtonType , self :: use_camel_case :: UseCamelCase , self :: use_fragment_syntax :: UseFragmentSyntax ,] } }
+declare_group! { pub (crate) Nursery { name : "nursery" , rules : [self :: no_array_index_key :: NoArrayIndexKey , self :: no_children_prop :: NoChildrenProp , self :: no_dangerously_set_inner_html :: NoDangerouslySetInnerHtml , self :: no_dangerously_set_inner_html_with_children :: NoDangerouslySetInnerHtmlWithChildren , self :: no_render_return_value :: NoRenderReturnValue , self :: no_restricted_globals :: NoRestrictedGlobals , self :: no_undeclared_variables :: NoUndeclaredVariables , self :: no_unused_variables :: NoUnusedVariables , self :: no_useless_fragments :: NoUselessFragments , self :: no_void_elements_with_children :: NoVoidElementsWithChildren , self :: use_button_type :: UseButtonType , self :: use_camel_case :: UseCamelCase , self :: use_fragment_syntax :: UseFragmentSyntax ,] } }

ADD
crates/rome_js_analyze/tests/specs/nursery/noRestrictedGlobals.js
+// invalid
+console.log(event);
+console.log(error);
+
+// valid
+function f(event, error) {
+ console.log(event);
+ console.log(error);
+}
\ No newline at end of file

MODIFY
crates/rome_js_semantic/src/semantic_model.rs
crates/rome_js_semantic/src/semantic_model.rs
@@ -507,6 +507,7 @@ impl<'a> FusedIterator for GlobalsReferencesIter<'a> {}
/// Iterate all bindings that were bound in a given scope. It **does
/// not** Returns bindings of parent scopes.
+#[derive(Debug)]
pub struct ScopeBindingsIter {
data: Arc<SemanticModelData>,
scope_id: usize,

MODIFY
crates/rome_service/src/configuration/linter/rules.rs
crates/rome_service/src/configuration/linter/rules.rs
@@ -393,6 +393,7 @@ struct NurserySchema {
no_dangerously_set_inner_html_with_children: Option<RuleConfiguration>,
no_new_symbol: Option<RuleConfiguration>,
no_render_return_value: Option<RuleConfiguration>,
+ no_restricted_globals: Option<RuleConfiguration>,
no_undeclared_variables: Option<RuleConfiguration>,
no_unreachable: Option<RuleConfiguration>,
no_unused_variables: Option<RuleConfiguration>,
@@ -407,7 +408,7 @@ struct NurserySchema {
}
impl Nursery {
const CATEGORY_NAME: &'static str = "nursery";
- pub(crate) const CATEGORY_RULES: [&'static str; 18] = [
+ pub(crate) const CATEGORY_RULES: [&'static str; 19] = [
"noArrayIndexKey",
"noAutofocus",
"noChildrenProp",
@@ -415,6 +416,7 @@ impl Nursery {
"noDangerouslySetInnerHtmlWithChildren",
"noNewSymbol",
"noRenderReturnValue",
+ "noRestrictedGlobals",
"noUndeclaredVariables",
"noUnreachable",
"noUnusedVariables",

MODIFY
editors/vscode/configuration_schema.json
editors/vscode/configuration_schema.json
}
]
},
+ "noRestrictedGlobals": {
+ "anyOf": [
+ {
+ "$ref": "#/definitions/RuleConfiguration"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
"noUndeclaredVariables": {
"anyOf": [
{

MODIFY
npm/backend-jsonrpc/src/workspace.ts
npm/backend-jsonrpc/src/workspace.ts
@@ -162,6 +162,7 @@ export interface Nursery {
noDangerouslySetInnerHtmlWithChildren?: RuleConfiguration;
noNewSymbol?: RuleConfiguration;
noRenderReturnValue?: RuleConfiguration;
+ noRestrictedGlobals?: RuleConfiguration;
noUndeclaredVariables?: RuleConfiguration;
noUnreachable?: RuleConfiguration;
noUnusedVariables?: RuleConfiguration;
@@ -312,6 +313,7 @@ export type Category =
| "lint/nursery/noAutofocus"
| "lint/nursery/useBlankTarget"
| "lint/nursery/useValidAnchor"
+ | "lint/nursery/noRestrictedGlobals"
| "lint/style/noNegationElse"
| "lint/style/noShoutyConstants"
| "lint/style/useSelfClosingElements"

feat(rome_js_analyze): new rule `noRestrictedGlobals` (#3342)