Skip to content

Commit 2afa0cf

Browse files
committed
get all tests passing
1 parent b3c3125 commit 2afa0cf

File tree

112 files changed

+1194
-342
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+1194
-342
lines changed

Cargo.lock

+333-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/oxc_linter/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ schemars = { workspace = true, features = ["indexmap2"] }
5757
static_assertions = { workspace = true }
5858
insta = { workspace = true }
5959
project-root = { workspace = true }
60+
markdown = { version = "1.0.0-alpha.18" }

crates/oxc_linter/src/rule.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,22 @@ impl RuleWithSeverity {
235235
#[cfg(test)]
236236
mod test {
237237
use crate::rules::RULES;
238+
use markdown::{to_html_with_options, Options};
238239

239240
#[test]
240241
fn ensure_documentation() {
241242
assert!(!RULES.is_empty());
243+
let options = Options::gfm();
244+
242245
for rule in RULES.iter() {
243-
assert!(rule.documentation().is_some_and(|s| !s.is_empty()), "{}", rule.name());
246+
let name = rule.name();
247+
assert!(
248+
rule.documentation().is_some_and(|s| !s.is_empty()),
249+
"Rule '{name}' is missing documentation."
250+
);
251+
// will panic if provided invalid markdown
252+
let html = to_html_with_options(rule.documentation().unwrap(), &options).unwrap();
253+
assert!(!html.is_empty());
244254
}
245255
}
246256
}

crates/oxc_linter/src/rules/eslint/for_direction.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ declare_oxc_lint!(
3535
/// ```javascript
3636
/// for (var i = 0; i < 10; i--) {}
3737
///
38-
/// for (var = 10; i >= 0; i++) {}
38+
/// for (var i = 10; i >= 0; i++) {}
3939
/// ```
4040
ForDirection,
4141
correctness,

crates/oxc_linter/src/rules/eslint/guard_for_in.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ declare_oxc_lint!(
2424
/// ### Example
2525
/// ```javascript
2626
/// for (key in foo) {
27-
// doSomething(key);
28-
// }
27+
/// doSomething(key);
28+
/// }
2929
/// ```
3030
GuardForIn,
3131
style

crates/oxc_linter/src/rules/eslint/max_lines.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,15 @@ impl Default for MaxLinesConfig {
3737

3838
declare_oxc_lint!(
3939
/// ### What it does
40-
/// Enforce a maximum number of lines per file
40+
/// Enforce a maximum number of lines per file.
4141
///
4242
/// ### Why is this bad?
4343
///
44-
/// Some people consider large files a code smell. Large files tend to do a lot of things and can make it hard following what’s going.
45-
/// While there is not an objective maximum number of lines considered acceptable in a file, most people would agree it should not be in the thousands. Recommendations usually range from 100 to 500 lines.
46-
///
47-
/// ### Example
48-
/// ```javascript
49-
/// ```
44+
/// Some people consider large files a code smell. Large files tend to do a
45+
/// lot of things and can make it hard following what’s going. While there
46+
/// is not an objective maximum number of lines considered acceptable in a
47+
/// file, most people would agree it should not be in the thousands.
48+
/// Recommendations usually range from 100 to 500 lines.
5049
MaxLines,
5150
pedantic
5251
);

crates/oxc_linter/src/rules/eslint/no_await_in_loop.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct NoAwaitInLoop;
1818
declare_oxc_lint!(
1919
/// ### What it does
2020
///
21-
/// This rule disallows the use of await within loop bodies. (for, for-in, for-of, while, do-while).
21+
/// This rule disallows the use of `await` within loop bodies. (for, for-in, for-of, while, do-while).
2222
///
2323
/// ### Why is this bad?
2424
///
@@ -28,14 +28,18 @@ declare_oxc_lint!(
2828
/// ### Example
2929
/// Bad:
3030
/// ```javascript
31-
/// for (const user of users) {
32-
/// const userRecord = await getUserRecord(user);
31+
/// async function bad() {
32+
/// for (const user of users) {
33+
/// const userRecord = await getUserRecord(user);
34+
/// }
3335
/// }
3436
/// ```
3537
///
3638
/// Good:
3739
/// ```javascript
38-
/// await Promise.all(users.map(user => getUserRecord(user)));
40+
/// async function good() {
41+
/// await Promise.all(users.map(user => getUserRecord(user)));
42+
/// }
3943
/// ```
4044
NoAwaitInLoop,
4145
perf

crates/oxc_linter/src/rules/eslint/no_case_declarations.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ declare_oxc_lint!(
2626
///
2727
/// ### Example
2828
/// ```javascript
29-
// switch (foo) {
30-
// case 1:
31-
// let x = 1;
32-
// break;
33-
// case 2:
34-
// const y = 2;
35-
// break;
36-
// case 3:
37-
// function f() {}
38-
// break;
39-
// default:
40-
// class C {}
41-
// }
29+
/// switch (foo) {
30+
/// case 1:
31+
/// let x = 1;
32+
/// break;
33+
/// case 2:
34+
/// const y = 2;
35+
/// break;
36+
/// case 3:
37+
/// function f() {}
38+
/// break;
39+
/// default:
40+
/// class C {}
41+
/// }
4242
/// ```
4343
NoCaseDeclarations,
4444
pedantic

crates/oxc_linter/src/rules/eslint/no_cond_assign.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,24 @@ enum NoCondAssignConfig {
2929
declare_oxc_lint!(
3030
/// ### What it does
3131
///
32+
/// Disallow assignment operators in conditional expressions
3233
///
3334
/// ### Why is this bad?
3435
///
36+
/// In conditional statements, it is very easy to mistype a comparison
37+
/// operator (such as `==`) as an assignment operator (such as `=`).
38+
///
39+
/// There are valid reasons to use assignment operators in conditional
40+
/// statements. However, it can be difficult to tell whether a specific
41+
/// assignment was intentional.
3542
///
3643
/// ### Example
37-
/// ```javascript
44+
///
45+
/// ```js
46+
/// // Check the user's job title
47+
/// if (user.jobTitle = "manager") {
48+
/// // user.jobTitle is now incorrect
49+
/// }
3850
/// ```
3951
NoCondAssign,
4052
correctness

crates/oxc_linter/src/rules/eslint/no_continue.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ declare_oxc_lint!(
2424
/// ### Example
2525
/// ```javascript
2626
/// var sum = 0,
27-
// i;
28-
//
29-
// for(i = 0; i < 10; i++) {
30-
// if(i >= 5) {
31-
// continue;
32-
// }
33-
//
34-
// sum += i;
35-
// }
27+
/// i;
28+
///
29+
/// for(i = 0; i < 10; i++) {
30+
/// if(i >= 5) {
31+
/// continue;
32+
/// }
33+
///
34+
/// sum += i;
35+
/// }
3636
/// ```
3737
NoContinue,
3838
style

crates/oxc_linter/src/rules/eslint/no_debugger.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ declare_oxc_lint!(
2121
/// They're most commonly an accidental debugging leftover.
2222
///
2323
/// ### Example
24+
///
2425
/// ```javascript
25-
/// const data = await getData();
26-
/// const result = complexCalculation(data);
27-
/// debugger;
26+
/// async function main() {
27+
/// const data = await getData();
28+
/// const result = complexCalculation(data);
29+
/// debugger;
30+
/// }
2831
/// ```
2932
NoDebugger,
3033
correctness,

crates/oxc_linter/src/rules/eslint/no_ex_assign.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ declare_oxc_lint!(
2525
///
2626
/// ### Example
2727
/// ```javascript
28-
// try {
29-
// // code
30-
// } catch (e) {
31-
// e = 10;
32-
// }
28+
/// try {
29+
/// // code
30+
/// } catch (e) {
31+
/// e = 10;
32+
/// }
3333
/// ```
3434
NoExAssign,
3535
correctness

crates/oxc_linter/src/rules/eslint/no_undefined.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@ declare_oxc_lint!(
2929
/// var undefined = "foo";
3030
///
3131
/// if (foo === undefined) {
32-
/// ...
32+
/// // ...
3333
/// }
3434
///
3535
/// function baz(undefined) {
36-
/// ...
36+
/// // ...
3737
/// }
3838
///
3939
/// bar(undefined, "lorem");
40-
///
4140
/// ```
4241
///
4342
/// ### Example of good code
@@ -47,7 +46,7 @@ declare_oxc_lint!(
4746
/// var Undefined = "foo";
4847
///
4948
/// if (typeof foo === "undefined") {
50-
/// ...
49+
/// // ...
5150
/// }
5251
///
5352
/// global.undefined = "foo";

crates/oxc_linter/src/rules/eslint/no_useless_escape.rs

+38
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,45 @@ declare_oxc_lint!(
2323
///
2424
///
2525
/// ### Example
26+
///
27+
/// Examples of **incorrect** code for this rule:
28+
///
29+
/// ```javascript
30+
/// /*eslint no-useless-escape: "error"*/
31+
///
32+
/// "\'";
33+
/// '\"';
34+
/// "\#";
35+
/// "\e";
36+
/// `\"`;
37+
/// `\"${foo}\"`;
38+
/// `\#{foo}`;
39+
/// /\!/;
40+
/// /\@/;
41+
/// /[\[]/;
42+
/// /[a-z\-]/;
43+
/// ```
44+
///
45+
/// Examples of **correct** code for this rule:
46+
///
2647
/// ```javascript
48+
/// /*eslint no-useless-escape: "error"*/
49+
///
50+
/// "\"";
51+
/// '\'';
52+
/// "\x12";
53+
/// "\u00a9";
54+
/// "\371";
55+
/// "xs\u2111";
56+
/// `\``;
57+
/// `\${${foo}}`;
58+
/// `$\{${foo}}`;
59+
/// /\\/g;
60+
/// /\t/g;
61+
/// /\w\$\*\^\./;
62+
/// /[[]/;
63+
/// /[\]]/;
64+
/// /[a-z-]/;
2765
/// ```
2866
NoUselessEscape,
2967
correctness,

crates/oxc_linter/src/rules/eslint/no_void.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ declare_oxc_lint!(
3030
/// var foo = void 0;
3131
///
3232
/// // success
33-
/// "var foo = bar()",
34-
/// "foo.void()",
35-
/// "foo.void = bar",
33+
/// "var foo = bar()";
34+
/// "foo.void()";
35+
/// "foo.void = bar";
3636
/// ```
3737
NoVoid,
3838
restriction,

crates/oxc_linter/src/rules/eslint/unicode_bom.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ declare_oxc_lint!(
3636
///
3737
/// ### Example
3838
/// ```javascript
39-
/// var a = 123;"
39+
/// var a = 123;
4040
/// ```
4141
UnicodeBom,
4242
restriction,

crates/oxc_linter/src/rules/import/named.rs

+46-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,55 @@ pub struct Named;
1818
declare_oxc_lint!(
1919
/// ### What it does
2020
///
21+
/// Verifies that all named imports are part of the set of named exports in
22+
/// the referenced module.
23+
///
24+
/// For `export`, verifies that all named exports exist in the referenced
25+
/// module.
26+
///
27+
/// Note: for packages, the plugin will find exported names from
28+
/// `jsnext:main` (deprecated) or `module`, if present in `package.json`.
29+
/// Redux's npm module includes this key, and thereby is lintable, for
30+
/// example.
31+
///
32+
/// A module path that is ignored or not unambiguously an ES module will not
33+
/// be reported when imported. Note that type imports and exports, as used
34+
/// by Flow, are always ignored.
35+
///
2136
/// ### Why is this bad?
2237
///
2338
/// ### Example
24-
/// ```javascript
39+
/// Given
40+
/// ```js
41+
/// // ./foo.js
42+
/// export const foo = "I'm so foo"
43+
/// ```
44+
///
45+
/// The following is considered valid:
46+
///
47+
/// ```js
48+
/// // ./bar.js
49+
/// import { foo } from './foo'
50+
///
51+
/// // ES7 proposal
52+
/// export { foo as bar } from './foo'
53+
///
54+
/// // node_modules without jsnext:main are not analyzed by default
55+
/// // (import/ignore setting)
56+
/// import { SomeNonsenseThatDoesntExist } from 'react'
57+
/// ```
58+
///
59+
/// ...and the following are reported:
60+
///
61+
/// ```js
62+
/// // ./baz.js
63+
/// import { notFoo } from './foo'
64+
///
65+
/// // ES7 proposal
66+
/// export { notFoo as defNotBar } from './foo'
67+
///
68+
/// // will follow 'jsnext:main', if available
69+
/// import { dontCreateStore } from 'redux'
2570
/// ```
2671
Named,
2772
correctness

crates/oxc_linter/src/rules/jest/no_conditional_expect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ declare_oxc_lint!(
4747
/// });
4848
///
4949
/// it('throws an error', async () => {
50-
// await foo().catch(error => expect(error).toBeInstanceOf(error));
51-
// });
50+
/// await foo().catch(error => expect(error).toBeInstanceOf(error));
51+
/// });
5252
/// ```
5353
///
5454
/// This rule is compatible with [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-conditional-expect.md),

0 commit comments

Comments
 (0)