Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_js_analyzer): promote nursery rules #4239

Merged
merged 10 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ try {

# Emitted Messages

```block
Skipped 1 suggested fixes.
If you wish to apply the suggested (unsafe) fixes, use the command rome check --apply-unsafe

```

```block
Fixed 1 file(s) in <TIME>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,7 @@ internalError/io ━━━━━━━━━━━━━━━━━━━━━
# Emitted Messages

```block
file.js:1:9 lint/complexity/useSimplifiedLogicExpression FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Logical expression contains unnecessary complexity.

> 1 │ let a = !b || !c
│ ^^^^^^^^

i Suggested fix: Reduce the complexity of the logical expression.

- let·a·=·!b·||·!c
+ let·a·=·!(b·&&·c)


```

```block
file.js:1:1 lint/nursery/useConst FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
file.js:1:1 lint/style/useConst FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× This 'let' declares a variable which is never re-assigned.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,20 @@ rome.json:6:13 configuration ━━━━━━━━━━━━━━━━━
- recommended
- noChildrenProp
- noConstAssign
- noConstructorReturn
- noEmptyPattern
- noNewSymbol
- noPrecisionLoss
- noRenderReturnValue
- noSetterReturn
- noStringCaseMismatch
- noUndeclaredVariables
- noUnnecessaryContinue
- noUnreachable
- noUnsafeFinally
- noUnusedVariables
- noVoidElementsWithChildren
- noVoidTypeReturn
- useValidForDirection


Expand Down
2 changes: 1 addition & 1 deletion crates/rome_diagnostics_categories/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use quote::{format_ident, quote};
use std::{env, fs, io, path::PathBuf};

macro_rules! define_dategories {
macro_rules! define_categories {
( $( $name_link:literal : $link:literal, )* ; $( $name:literal , )* ) => {
const CATEGORIES: &[(&str, Option<&str>)] = &[
$( ($name_link, Some($link)), )*
Expand Down
52 changes: 30 additions & 22 deletions crates/rome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// This file contains the list of all diagnostic categories for the Rome
// toolchain
//
// The `define_dategories` macro is preprocessed in the build script for the
// The `define_categories` macro is preprocessed in the build script for the
// crate in order to generate the static registry. The body of the macro
// consists of a list of key-value pairs defining the categories that have an
// associated hyperlink, then a list of string literals defining the remaining
// categories without a link.

define_dategories! {
define_categories! {
// Lint categories
// a11y group
"lint/a11y/noAutofocus": "https://docs.rome.tools/lint/rules/noAutofocus",
Expand All @@ -20,6 +20,9 @@ define_dategories! {
"lint/a11y/useKeyWithMouseEvents": "https://docs.rome.tools/lint/rules/useKeyWithMouseEvents",
"lint/a11y/useValidAnchor": "https://docs.rome.tools/lint/rules/useValidAnchor",
"lint/a11y/useHtmlLang": "https://docs.rome.tools/lint/rules/useHtmlLang",
"lint/a11y/noDistractingElements": "https://docs.rome.tools/lint/rules/noDistractingElements",
"lint/a11y/noHeaderScope": "https://docs.rome.tools/lint/rules/noHeaderScope",
"lint/a11y/noAccessKey": "https://docs.rome.tools/lint/rules/noAccessKey",

// complexity
"lint/complexity/noExtraBooleanCast": "https://docs.rome.tools/lint/rules/noExtraBooleanCast",
Expand All @@ -41,60 +44,47 @@ define_dategories! {
"lint/correctness/noUnusedVariables": "https://docs.rome.tools/lint/rules/noUnusedVariables",
"lint/correctness/noVoidElementsWithChildren": "https://docs.rome.tools/lint/rules/noVoidElementsWithChildren",
"lint/correctness/useValidForDirection": "https://docs.rome.tools/lint/rules/useValidForDirection",
"lint/correctness/noUnsafeFinally": "https://docs.rome.tools/lint/rules/noUnsafeFinally",
"lint/correctness/noConstructorReturn": "https://docs.rome.tools/lint/rules/noConstructorReturn",
"lint/correctness/noPrecisionLoss": "https://docs.rome.tools/lint/rules/noPrecisionLoss",
"lint/correctness/noVoidTypeReturn": "https://docs.rome.tools/lint/rules/noVoidTypeReturn",
"lint/correctness/noStringCaseMismatch": "https://docs.rome.tools/lint/rules/noStringCaseMismatch",
"lint/correctness/noSetterReturn": "https://docs.rome.tools/lint/rules/noSetterReturn",


// nursery
"lint/nursery/noAccessKey": "https://docs.rome.tools/lint/rules/noAccessKey",
"lint/nursery/noAssignInExpressions": "https://docs.rome.tools/lint/rules/noAssignInExpressions",
"lint/nursery/noWith": "https://docs.rome.tools/lint/rules/noWith",
"lint/nursery/noExtraSemicolons": "https://docs.rome.tools/lint/rules/noExtraSemicolons",
"lint/nursery/noBannedTypes":"https://docs.rome.tools/lint/rules/noBannedTypes",
"lint/nursery/noClassAssign": "https://docs.rome.tools/lint/rules/noClassAssign",
"lint/nursery/noCommaOperator": "https://docs.rome.tools/lint/rules/noCommaOperator",
"lint/nursery/noConstEnum": "https://docs.rome.tools/lint/rules/noConstEnum",
"lint/nursery/noConstructorReturn": "https://docs.rome.tools/lint/rules/noConstructorReturn",
"lint/nursery/noDistractingElements": "https://docs.rome.tools/lint/rules/noDistractingElements",
"lint/nursery/noDuplicateCase": "https://docs.rome.tools/lint/rules/noDuplicateCase",
"lint/nursery/noDuplicateObjectKeys":"https://docs.rome.tools/lint/rules/noDuplicateObjectKeys",
"lint/nursery/noEmptyInterface": "https://docs.rome.tools/lint/rules/noEmptyInterface",
"lint/nursery/noExtraLabels":"https://docs.rome.tools/lint/rules/noExtraLabels",
"lint/nursery/noExtraNonNullAssertion":"https://docs.rome.tools/lint/rules/noExtraNonNullAssertion",
"lint/nursery/noHeaderScope": "https://docs.rome.tools/lint/rules/noHeaderScope",
"lint/nursery/noInferrableTypes": "https://docs.rome.tools/lint/rules/noInferrableTypes",
"lint/nursery/noInnerDeclarations": "https://docs.rome.tools/lint/rules/noInnerDeclarations",
"lint/nursery/noInvalidConstructorSuper": "https://docs.rome.tools/lint/rules/noInvalidConstructorSuper",
"lint/nursery/noConfusingLabels": "https://docs.rome.tools/lint/rules/noConfusingLabels",
"lint/nursery/noNonNullAssertion": "https://docs.rome.tools/lint/rules/noNonNullAssertion",
"lint/nursery/noParameterProperties": "https://docs.rome.tools/lint/rules/noParameterProperties",
"lint/nursery/noPrecisionLoss": "https://docs.rome.tools/lint/rules/noPrecisionLoss",
"lint/nursery/noRedundantAlt": "https://docs.rome.tools/lint/rules/noRedundantAlt",
"lint/nursery/noRedundantUseStrict": "https://docs.rome.tools/lint/rules/noRedundantUseStrict",
"lint/nursery/noRestrictedGlobals": "https://docs.rome.tools/lint/rules/noRestrictedGlobals",
"lint/nursery/noSelfCompare": "https://docs.rome.tools/lint/rules/noSelfCompare",
"lint/nursery/noSelfAssignment": "https://docs.rome.tools/lint/rules/noSelfAssignment",
"lint/nursery/noSetterReturn": "https://docs.rome.tools/lint/rules/noSetterReturn",
"lint/nursery/noStringCaseMismatch": "https://docs.rome.tools/lint/rules/noStringCaseMismatch",
"lint/nursery/noSwitchDeclarations": "https://docs.rome.tools/lint/rules/noSwitchDeclarations",
"lint/nursery/noUnreachableSuper": "https://rome.tools/docs/lint/rules/noUnreachableSuper",
"lint/nursery/noUnsafeFinally": "https://docs.rome.tools/lint/rules/noUnsafeFinally",
"lint/nursery/noUnusedLabels": "https://docs.rome.tools/lint/rules/noUnusedLabels",
"lint/nursery/noUselessSwitchCase": "https://docs.rome.tools/lint/rules/noUselessSwitchCase",
"lint/nursery/noVar": "https://docs.rome.tools/lint/rules/noVar",
"lint/nursery/noVoidTypeReturn": "https://docs.rome.tools/lint/rules/noVoidTypeReturn",
"lint/nursery/useAriaPropsForRole": "https://docs.rome.tools/lint/rules/useAriaPropsForRole",
"lint/nursery/useAriaPropTypes": "https://docs.rome.tools/lint/rules/useAriaPropTypes",
"lint/nursery/useCamelCase": "https://docs.rome.tools/lint/rules/useCamelCase",
"lint/nursery/useConst":"https://docs.rome.tools/lint/rules/useConst",
"lint/nursery/useValidLang":"https://docs.rome.tools/lint/rules/useValidLang",
"lint/nursery/useDefaultParameterLast":"https://docs.rome.tools/lint/rules/useDefaultParameterLast",
"lint/nursery/useDefaultSwitchClauseLast":"https://docs.rome.tools/lint/rules/useDefaultSwitchClauseLast",
"lint/nursery/useEnumInitializers":"https://docs.rome.tools/lint/rules/useEnumInitializers",
"lint/nursery/useValidAriaProps":"https://docs.rome.tools/lint/rules/useValidAriaProps",
"lint/nursery/useExhaustiveDependencies": "https://docs.rome.tools/lint/rules/useExhaustiveDependencies",
"lint/nursery/useExponentiationOperator": "https://docs.rome.tools/lint/rules/useExponentiationOperator",
"lint/nursery/useIsNan": "https://docs.rome.tools/lint/rules/useIsNan",
"lint/nursery/useMediaCaption": "https://docs.rome.tools/lint/rules/useMediaCaption",
"lint/nursery/useIframeTitle": "https://docs.rome.tools/lint/rules/useIframeTitle",
"lint/nursery/useNumericLiterals": "https://docs.rome.tools/lint/rules/useNumericLiterals",
"lint/nursery/noNoninteractiveElementToInteractiveRole": "https://docs.rome.tools/lint/rules/noNoninteractiveElementToInteractiveRole",
"lint/nursery/noUselessRename": "https://docs.rome.tools/lint/rules/noUselessRename",
"lint/nursery/useValidForDirection": "https://docs.rome.tools/lint/rules/useValidForDirection",
Expand Down Expand Up @@ -131,6 +121,14 @@ define_dategories! {
"lint/style/useSingleVarDeclarator": "https://docs.rome.tools/lint/rules/useSingleVarDeclarator",
"lint/style/useTemplate": "https://docs.rome.tools/lint/rules/useTemplate",
"lint/style/useWhile": "https://docs.rome.tools/lint/rules/useWhile",
"lint/style/useExponentiationOperator": "https://docs.rome.tools/lint/rules/useExponentiationOperator",
"lint/style/useNumericLiterals": "https://docs.rome.tools/lint/rules/useNumericLiterals",
"lint/style/useDefaultParameterLast":"https://docs.rome.tools/lint/rules/useDefaultParameterLast",
"lint/style/useConst":"https://docs.rome.tools/lint/rules/useConst",
"lint/style/noVar": "https://docs.rome.tools/lint/rules/noVar",
"lint/style/noNonNullAssertion": "https://docs.rome.tools/lint/rules/noNonNullAssertion",
"lint/style/useEnumInitializers":"https://docs.rome.tools/lint/rules/useEnumInitializers",


// suspicious
"lint/suspicious/noArrayIndexKey": "https://docs.rome.tools/lint/rules/noArrayIndexKey",
Expand All @@ -149,8 +147,18 @@ define_dategories! {
"lint/suspicious/noSparseArray": "https://docs.rome.tools/lint/rules/noSparseArray",
"lint/suspicious/noUnsafeNegation": "https://docs.rome.tools/lint/rules/noUnsafeNegation",
"lint/suspicious/useValidTypeof": "https://docs.rome.tools/lint/rules/useValidTypeof",
"lint/suspicious/noEmptyInterface": "https://docs.rome.tools/lint/rules/noEmptyInterface",
"lint/suspicious/noExtraNonNullAssertion":"https://docs.rome.tools/lint/rules/noExtraNonNullAssertion",
"lint/suspicious/noRedundantUseStrict": "https://docs.rome.tools/lint/rules/noRedundantUseStrict",
"lint/suspicious/noConstEnum": "https://docs.rome.tools/lint/rules/noConstEnum",
"lint/suspicious/useDefaultSwitchClauseLast":"https://docs.rome.tools/lint/rules/useDefaultSwitchClauseLast",
"lint/suspicious/noDuplicateObjectKeys":"https://docs.rome.tools/lint/rules/noDuplicateObjectKeys",



;


// General categories
"files/missingHandler",
"format",
Expand Down
7 changes: 7 additions & 0 deletions crates/rome_fs/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub trait FileSystem: Send + Sync + RefUnwindSafe {
fn config_name(&self) -> &str {
CONFIG_NAME
}

/// Return the path to the working directory
fn working_directory(&self) -> Option<PathBuf>;
}

pub trait File {
Expand Down Expand Up @@ -165,6 +168,10 @@ where
fn traversal<'scope>(&'scope self, func: BoxedTraversal<'_, 'scope>) {
T::traversal(self, func)
}

fn working_directory(&self) -> Option<PathBuf> {
T::working_directory(self)
}
}

#[derive(Debug, Diagnostic)]
Expand Down
4 changes: 4 additions & 0 deletions crates/rome_fs/src/fs/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ impl FileSystem for MemoryFileSystem {
fn traversal<'scope>(&'scope self, func: BoxedTraversal<'_, 'scope>) {
func(&MemoryTraversalScope { fs: self })
}

fn working_directory(&self) -> Option<PathBuf> {
None
}
}

struct MemoryFile {
Expand Down
5 changes: 5 additions & 0 deletions crates/rome_fs/src/fs/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rayon::{scope, Scope};
use rome_diagnostics::{adapters::IoError, DiagnosticExt, Error};
use std::fs::DirEntry;
use std::{
env,
ffi::OsStr,
fs,
io::{self, ErrorKind as IoErrorKind, Read, Seek, Write},
Expand All @@ -35,6 +36,10 @@ impl FileSystem for OsFileSystem {
func(scope);
})
}

fn working_directory(&self) -> Option<PathBuf> {
env::current_dir().ok()
}
}

struct OsFile {
Expand Down
5 changes: 4 additions & 1 deletion crates/rome_js_analyze/src/analyzers/a11y.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ declare_rule! {
pub(crate) UseSimplifiedLogicExpression {
version: "0.7.0",
name: "useSimplifiedLogicExpression",
recommended: true,
recommended: false,
}
}

Expand Down
8 changes: 7 additions & 1 deletion crates/rome_js_analyze/src/analyzers/correctness.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ declare_rule! {
pub(crate) NoPrecisionLoss {
version: "11.0.0",
name: "noPrecisionLoss",
recommended: false,
recommended: true,
}
}

Expand Down
Loading