Skip to content
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

refactor(lint): move lint rule docs to cli/tools/lint/docs/ #27293

Closed
Closed
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
40 changes: 40 additions & 0 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ pub struct LintFlags {
pub json: bool,
pub compact: bool,
pub watch: Option<WatchFlags>,
pub internal_print_all_rules: bool,
Copy link
Member

@dsherret dsherret Dec 10, 2024

Choose a reason for hiding this comment

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

I don't think we need this? We can add a unit test that does this linting in tools/lint?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not until #27245 lands, there's no way to get all available rules right now and print them.

Copy link
Member

@dsherret dsherret Dec 10, 2024

Choose a reason for hiding this comment

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

I think we can use LintRuleProvider and instead write a unit test?

pub struct LintRuleProvider {

}

impl LintFlags {
Expand Down Expand Up @@ -2901,6 +2902,12 @@ To ignore linting on an entire file, you can add an ignore comment at the top of
.action(ArgAction::Append)
.value_hint(ValueHint::AnyPath),
)
.arg(
Arg::new("internal-print-all-rules")
.long("internal-print-all-rules")
.action(ArgAction::SetTrue)
.hide(true)
)
.arg(watch_arg(false))
.arg(watch_exclude_arg())
.arg(no_clear_screen_arg())
Expand Down Expand Up @@ -5110,6 +5117,7 @@ fn lint_parse(

let json = matches.get_flag("json");
let compact = matches.get_flag("compact");
let internal_print_all_rules = matches.get_flag("internal-print-all-rules");

flags.subcommand = DenoSubcommand::Lint(LintFlags {
files: FileFlags {
Expand All @@ -5124,6 +5132,7 @@ fn lint_parse(
json,
compact,
watch: watch_arg_parse(matches)?,
internal_print_all_rules,
});
Ok(())
}
Expand Down Expand Up @@ -7133,6 +7142,7 @@ mod tests {
json: false,
compact: false,
watch: Default::default(),
internal_print_all_rules: false,
}),
..Flags::default()
}
Expand Down Expand Up @@ -7161,6 +7171,7 @@ mod tests {
json: false,
compact: false,
watch: Some(Default::default()),
internal_print_all_rules: false,
}),
..Flags::default()
}
Expand Down Expand Up @@ -7194,6 +7205,7 @@ mod tests {
no_clear_screen: true,
exclude: vec![],
}),
internal_print_all_rules: false,
}),
..Flags::default()
}
Expand Down Expand Up @@ -7221,6 +7233,7 @@ mod tests {
json: false,
compact: false,
watch: Default::default(),
internal_print_all_rules: false,
}),
..Flags::default()
}
Expand All @@ -7243,6 +7256,7 @@ mod tests {
json: false,
compact: false,
watch: Default::default(),
internal_print_all_rules: false,
}),
..Flags::default()
}
Expand Down Expand Up @@ -7270,6 +7284,7 @@ mod tests {
json: false,
compact: false,
watch: Default::default(),
internal_print_all_rules: false,
}),
..Flags::default()
}
Expand Down Expand Up @@ -7298,6 +7313,7 @@ mod tests {
json: false,
compact: false,
watch: Default::default(),
internal_print_all_rules: false,
}),
..Flags::default()
}
Expand All @@ -7320,6 +7336,7 @@ mod tests {
json: true,
compact: false,
watch: Default::default(),
internal_print_all_rules: false,
}),
..Flags::default()
}
Expand Down Expand Up @@ -7349,6 +7366,7 @@ mod tests {
json: true,
compact: false,
watch: Default::default(),
internal_print_all_rules: false,
}),
config_flag: ConfigFlag::Path("Deno.jsonc".to_string()),
..Flags::default()
Expand Down Expand Up @@ -7379,11 +7397,33 @@ mod tests {
json: false,
compact: true,
watch: Default::default(),
internal_print_all_rules: false,
}),
config_flag: ConfigFlag::Path("Deno.jsonc".to_string()),
..Flags::default()
}
);

let r =
flags_from_vec(svec!["deno", "lint", "--internal-print-all-rules",]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Lint(LintFlags {
files: FileFlags::default(),
fix: false,
rules: false,
maybe_rules_tags: None,
maybe_rules_include: None,
maybe_rules_exclude: None,
json: false,
compact: false,
watch: Default::default(),
internal_print_all_rules: true,
}),
..Flags::default()
}
);
}

#[test]
Expand Down
5 changes: 4 additions & 1 deletion cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ async fn run_subcommand(flags: Arc<Flags>) -> Result<i32, AnyError> {
lsp::start().await
}),
DenoSubcommand::Lint(lint_flags) => spawn_subcommand(async {
if lint_flags.rules {
if lint_flags.internal_print_all_rules {
tools::lint::internal_print_all_rules();
Ok(())
} else if lint_flags.rules {
tools::lint::print_rules_list(
lint_flags.json,
lint_flags.maybe_rules_tags,
Expand Down
6 changes: 3 additions & 3 deletions cli/schemas/config-file.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
"type": "array",
"description": "List of tag names that will be run. Empty list disables all tags and will only use rules from `include`.",
"items": {
"$ref": "https://raw.githubusercontent.com/denoland/deno_lint/main/schemas/tags.v1.json"
"$ref": "https://deno.land/x/deno/cli/schemas/lint-tags.v1.json"
},
"minItems": 0,
"uniqueItems": true
Expand All @@ -300,7 +300,7 @@
"type": "array",
"description": "List of rule names that will be excluded from configured tag sets. If the same rule is in `include` it will be run.",
"items": {
"$ref": "https://raw.githubusercontent.com/denoland/deno_lint/main/schemas/rules.v1.json"
"$ref": "https://deno.land/x/deno/cli/schemas/lint-rules.v1.json"
},
"minItems": 0,
"uniqueItems": true
Expand All @@ -309,7 +309,7 @@
"type": "array",
"description": "List of rule names that will be run. Even if the same rule is in `exclude` it will be run.",
"items": {
"$ref": "https://raw.githubusercontent.com/denoland/deno_lint/main/schemas/rules.v1.json"
"$ref": "https://deno.land/x/deno/cli/schemas/lint-rules.v1.json"
},
"minItems": 0,
"uniqueItems": true
Expand Down
113 changes: 113 additions & 0 deletions cli/schemas/lint-rules.v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"enum": [
"adjacent-overload-signatures",
"ban-ts-comment",
"ban-types",
"ban-unknown-rule-code",
"ban-untagged-ignore",
"ban-untagged-todo",
"ban-unused-ignore",

"camelcase",
"constructor-super",
"default-param-last",
"eqeqeq",
"explicit-function-return-type",
"explicit-module-boundary-types",
"for-direction",
"fresh-handler-export",
"fresh-server-event-handlers",
"getter-return",
"guard-for-in",
"no-array-constructor",
"no-async-promise-executor",
"no-await-in-loop",
"no-await-in-sync-fn",
"no-boolean-literal-for-arguments",
"no-case-declarations",
"no-class-assign",
"no-compare-neg-zero",
"no-cond-assign",
"no-console",
"no-const-assign",
"no-constant-condition",
"no-control-regex",
"no-debugger",
"no-delete-var",
"no-deprecated-deno-api",
"no-dupe-args",
"no-dupe-class-members",
"no-dupe-else-if",
"no-dupe-keys",
"no-duplicate-case",
"no-empty",
"no-empty-character-class",
"no-empty-enum",
"no-empty-interface",
"no-empty-pattern",
"no-eval",
"no-ex-assign",
"no-explicit-any",
"no-external-import",
"no-extra-boolean-cast",
"no-extra-non-null-assertion",
"no-fallthrough",
"no-func-assign",
"no-global-assign",
"no-implicit-declare-namespace-export",
"no-import-assertions",
"no-import-assign",
"no-inferrable-types",
"no-inner-declarations",
"no-invalid-regexp",
"no-invalid-triple-slash-reference",
"no-irregular-whitespace",
"no-misused-new",
"no-namespace",
"no-new-symbol",
"no-node-globals",
"no-non-null-asserted-optional-chain",
"no-non-null-assertion",
"no-obj-calls",
"no-octal",
"no-process-globals",
"no-prototype-builtins",
"no-redeclare",
"no-regex-spaces",
"no-self-assign",
"no-self-compare",
"no-setter-return",
"no-shadow-restricted-names",
"no-sloppy-imports",
"no-slow-types",
"no-sparse-arrays",
"no-sync-fn-in-async-fn",
"no-this-alias",
"no-this-before-super",
"no-throw-literal",
"no-top-level-await",
"no-undef",
"no-unreachable",
"no-unsafe-finally",
"no-unsafe-negation",
"no-unused-labels",
"no-unused-vars",
"no-var",
"no-window",
"no-window-prefix",
"no-with",
"prefer-as-const",
"prefer-ascii",
"prefer-const",
"prefer-namespace-keyword",
"prefer-primordials",
"require-await",
"require-yield",
"single-var-declarator",
"triple-slash-reference",
"use-isnan",
"valid-typeof",
"verbatim-module-syntax"
]
}
4 changes: 4 additions & 0 deletions cli/schemas/lint-tags.v1.json
Copy link
Member Author

Choose a reason for hiding this comment

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

This is not yet automated and tested, waiting on #27162 to land so appropriate APIs are available.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"enum": ["fresh", "jsr", "jsx", "react", "recommended"]
}
80 changes: 80 additions & 0 deletions cli/tools/lint/docs/adjacent_overload_signatures.md
Copy link
Member

@dsherret dsherret Dec 10, 2024

Choose a reason for hiding this comment

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

I don't think we should store these docs here. They're docs are for lint rules that live in deno_lint, so they should either live there or we should move all these docs to the deno-docs repo. Edit: It probably makes most sense to move these to deno-docs because these are for deno-docs.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Requires overload signatures to be adjacent to each other.

Overloaded signatures which are not next to each other can lead to code which is
hard to read and maintain.

### Invalid:

(`bar` is declared in-between `foo` overloads)

```typescript
type FooType = {
foo(s: string): void;
foo(n: number): void;
bar(): void;
foo(sn: string | number): void;
};
```

```typescript
interface FooInterface {
foo(s: string): void;
foo(n: number): void;
bar(): void;
foo(sn: string | number): void;
}
```

```typescript
class FooClass {
foo(s: string): void;
foo(n: number): void;
bar(): void {}
foo(sn: string | number): void {}
}
```

```typescript
export function foo(s: string): void;
export function foo(n: number): void;
export function bar(): void {}
export function foo(sn: string | number): void {}
```

### Valid:

(`bar` is declared after `foo`)

```typescript
type FooType = {
foo(s: string): void;
foo(n: number): void;
foo(sn: string | number): void;
bar(): void;
};
```

```typescript
interface FooInterface {
foo(s: string): void;
foo(n: number): void;
foo(sn: string | number): void;
bar(): void;
}
```

```typescript
class FooClass {
foo(s: string): void;
foo(n: number): void;
foo(sn: string | number): void {}
bar(): void {}
}
```

```typescript
export function foo(s: string): void;
export function foo(n: number): void;
export function foo(sn: string | number): void {}
export function bar(): void {}
```
Loading
Loading