Skip to content

Commit f3e0830

Browse files
committed
🚨 update linter with some more rules.
1 parent 4367b00 commit f3e0830

20 files changed

Lines changed: 144 additions & 53 deletions

β€Ž@coven/iterables/async/take.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const take = (
2828
yield item;
2929
count += 1n;
3030
} else {
31-
break;
31+
return;
3232
}
3333
}
3434
}

β€Ž@coven/iterables/async/zip.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const zip = <ItemFirst>(
3232
.next();
3333

3434
if (done) {
35-
break;
35+
return;
3636
}
3737

3838
yield [itemFirst as ItemFirst, value] as const;

β€Ž@coven/iterables/zip.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const zip = <ItemFirst>(
2828
const { done = false, value } = iteratorSecond.next();
2929

3030
if (done) {
31-
break;
31+
return;
3232
}
3333

3434
yield [itemFirst, value as ItemSecond];

β€Žlint/mod.tsβ€Ž

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
1+
import { maxLines } from "./rules/max-lines.ts";
2+
import { noBreak } from "./rules/no-break.ts";
13
import { noClass } from "./rules/no-class.ts";
4+
import { noContinue } from "./rules/no-continue.ts";
5+
import { noDefaultExport } from "./rules/no-default-export.ts";
6+
import { noDoWhile } from "./rules/no-do-while.ts";
7+
import { noEnum } from "./rules/no-enum.ts";
8+
import { noForIn } from "./rules/no-for-in.ts";
9+
import { noFunction } from "./rules/no-function.ts";
210
import { noNull } from "./rules/no-null.ts";
11+
import { noSwitch } from "./rules/no-switch.ts";
312
import { noThis } from "./rules/no-this.ts";
413
import { noThrow } from "./rules/no-throw.ts";
514
import { noTry } from "./rules/no-try.ts";
15+
import { noWhile } from "./rules/no-while.ts";
616

17+
// deno-lint-ignore coven/no-default-export
718
export default {
819
name: "coven",
920
rules: {
21+
"max-lines": maxLines,
22+
"no-break": noBreak,
1023
"no-class": noClass,
24+
"no-continue": noContinue,
25+
"no-default-export": noDefaultExport,
26+
"no-do-while": noDoWhile,
27+
"no-enum": noEnum,
28+
"no-for-in": noForIn,
29+
"no-function": noFunction,
1130
"no-null": noNull,
31+
"no-switch": noSwitch,
1232
"no-this": noThis,
1333
"no-throw": noThrow,
1434
"no-try": noTry,
35+
"no-while": noWhile,
1536
},
1637
} satisfies Deno.lint.Plugin;

β€Žlint/no.tsβ€Ž

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Utility type to figure out what the Node type is based on the Visitor.
3+
*/
4+
type FindContext<
5+
Visitor extends keyof Deno.lint.LintVisitor,
6+
Node extends Deno.lint.Node = Deno.lint.Node,
7+
> = Node extends { type: Visitor } ? Node : never;
8+
9+
/**
10+
* Shorthand for common "Avoid this, do that." lintinrg rules.
11+
*/
12+
export const no = <Visitor extends keyof Deno.lint.LintVisitor>(
13+
visitor: Visitor,
14+
message: string,
15+
condition?: (
16+
data: { context: Deno.lint.RuleContext; node: FindContext<Visitor> },
17+
) => boolean,
18+
): Deno.lint.Rule => ({
19+
create: (context): Deno.lint.LintVisitor => ({
20+
[visitor]: (node: FindContext<Visitor>): void => {
21+
(condition?.({ context, node }) ?? true)
22+
? context.report({ message, node })
23+
: undefined;
24+
},
25+
}),
26+
});

β€Žlint/rules/max-lines.tsβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { no } from "../no.ts";
2+
3+
const LINE_LIMIT = 300;
4+
5+
export const maxLines: Deno.lint.Rule = no(
6+
"Program",
7+
`Avoid large files. Split this into smaller files (${LINE_LIMIT} lines or less).`,
8+
({ context }) => context.sourceCode.text.split("\n").length > LINE_LIMIT,
9+
);

β€Žlint/rules/no-break.tsβ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { no } from "../no.ts";
2+
3+
export const noBreak: Deno.lint.Rule = no(
4+
"BreakStatement",
5+
"Avoid using `break`. Use explicit control flow.",
6+
);

β€Žlint/rules/no-class.tsβ€Ž

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
export const noClass: Deno.lint.Rule = {
2-
create: (context): Deno.lint.LintVisitor => ({
3-
ClassExpression: (node) => {
4-
context.report({
5-
node,
6-
message: "Avoid using `class`. Use a function instead.",
7-
});
8-
},
9-
}),
10-
};
1+
import { no } from "../no.ts";
2+
3+
export const noClass: Deno.lint.Rule = no(
4+
"ClassExpression",
5+
"Avoid using `class`. Use a function instead.",
6+
);

β€Žlint/rules/no-continue.tsβ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { no } from "../no.ts";
2+
3+
export const noContinue: Deno.lint.Rule = no(
4+
"ContinueStatement",
5+
"Avoid using `continue`. Use explicit control flow.",
6+
);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { no } from "../no.ts";
2+
3+
export const noDefaultExport: Deno.lint.Rule = no(
4+
"ExportDefaultDeclaration",
5+
"Avoid using default exports. Use named exports instead.",
6+
);

0 commit comments

Comments
Β (0)