@fenge/eslint-plugin 0.4.0 → 0.4.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/index.d.ts +4 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +5 -1
  4. package/dist/rules/call-arguments-length.d.ts.map +1 -1
  5. package/dist/rules/call-arguments-length.js +24 -3
  6. package/dist/rules/consistent-hashbang-and-filename.d.ts +6 -0
  7. package/dist/rules/consistent-hashbang-and-filename.d.ts.map +1 -0
  8. package/dist/rules/consistent-hashbang-and-filename.js +39 -0
  9. package/dist/rules/no-instanceof-builtin.d.ts.map +1 -1
  10. package/dist/rules/no-instanceof-builtin.js +3 -2
  11. package/dist/rules/no-nested-class.js +3 -2
  12. package/dist/rules/no-nested-function.js +3 -2
  13. package/dist/rules/no-restricted-loops.d.ts.map +1 -1
  14. package/dist/rules/no-restricted-loops.js +3 -3
  15. package/dist/rules/no-top-level-arrow-function.d.ts.map +1 -1
  16. package/dist/rules/no-top-level-arrow-function.js +3 -2
  17. package/dist/rules/no-triple-slash-directive.d.ts +6 -0
  18. package/dist/rules/no-triple-slash-directive.d.ts.map +1 -0
  19. package/dist/rules/no-triple-slash-directive.js +34 -0
  20. package/dist/rules/no-unnecessary-template-string.d.ts.map +1 -1
  21. package/dist/rules/no-unnecessary-template-string.js +3 -2
  22. package/dist/utils.d.ts +3 -0
  23. package/dist/utils.d.ts.map +1 -1
  24. package/dist/utils.js +4 -1
  25. package/package.json +7 -5
  26. package/CHANGELOG.md +0 -46
  27. package/doc/rules/call-arguments-length.md +0 -52
  28. package/doc/rules/no-instanceof-builtin.md +0 -50
  29. package/doc/rules/no-nested-class.md +0 -31
  30. package/doc/rules/no-nested-function.md +0 -42
  31. package/doc/rules/no-restricted-loops.md +0 -23
  32. package/doc/rules/no-top-level-arrow-function.md +0 -45
  33. package/doc/rules/no-unnecessary-template-string.md +0 -34
  34. package/src/index.ts +0 -17
  35. package/src/rules/call-arguments-length.test.ts +0 -48
  36. package/src/rules/call-arguments-length.ts +0 -163
  37. package/src/rules/no-instanceof-builtin.test.ts +0 -48
  38. package/src/rules/no-instanceof-builtin.ts +0 -46
  39. package/src/rules/no-nested-class.test.ts +0 -27
  40. package/src/rules/no-nested-class.ts +0 -31
  41. package/src/rules/no-nested-function.test.ts +0 -49
  42. package/src/rules/no-nested-function.ts +0 -32
  43. package/src/rules/no-restricted-loops.test.ts +0 -13
  44. package/src/rules/no-restricted-loops.ts +0 -30
  45. package/src/rules/no-top-level-arrow-function.test.ts +0 -32
  46. package/src/rules/no-top-level-arrow-function.ts +0 -35
  47. package/src/rules/no-unnecessary-template-string.test.ts +0 -25
  48. package/src/rules/no-unnecessary-template-string.ts +0 -29
  49. package/src/utils.ts +0 -7
  50. package/tsconfig.json +0 -5
@@ -1,49 +0,0 @@
1
- import { test } from "@fenge/dev-utils";
2
- import { noNestedFunction } from "./no-nested-function.ts";
3
-
4
- const valid = [
5
- // normal
6
- "function foo(){}",
7
- "const foo = () => {}",
8
-
9
- // export
10
- "export function foo() {}",
11
- "export default function foo() {}",
12
- "export default function() {}",
13
-
14
- // class
15
- "class Foo{bar(){}}",
16
- ];
17
-
18
- const invalid = [
19
- // normal
20
- "Foo.prototype.bar = function(){}",
21
- "Foo.prototype.bar = function bar(){}",
22
- "const foo = function(){}",
23
- "const foo = function foo(){}",
24
- "let foo; foo = function(){}",
25
- "let foo; foo = function foo(){}",
26
- "(function(){})",
27
-
28
- // nested
29
- "const foo = () => {function bar(){}}",
30
- "function foo() {function bar(){}}",
31
- "function foo() {let bar = function(){}}",
32
- "function foo() {let bar = function bar(){}}",
33
- "if(true) function foo(){}",
34
-
35
- // class
36
- "class Foo{bar = function(){}}",
37
- "class Foo{bar = function bar(){}}",
38
-
39
- // object
40
- "const foo = {bar: function() {}}",
41
- "const foo = {bar: function bar() {}}",
42
- "const foo = {bar() {}}", // disallow this case
43
-
44
- // callback
45
- "setTimeout(function(){},100)",
46
- "setTimeout(function callback(){},100)",
47
- ];
48
-
49
- test({ valid, invalid, ...noNestedFunction });
@@ -1,32 +0,0 @@
1
- import type { Rule } from "eslint";
2
- import type { Node } from "estree";
3
- import { getRuleName } from "../utils.ts";
4
-
5
- const name = getRuleName(import.meta.url);
6
- const rule: Rule.RuleModule = {
7
- meta: {
8
- docs: {
9
- description:
10
- "Non top-level functions are expected to be arrow functions instead of function declarations.",
11
- },
12
- messages: {
13
- [`${name}/error`]:
14
- "Non top-level functions are expected to be arrow functions instead of function declarations.",
15
- },
16
- },
17
- create: (context) => {
18
- const handle = (node: Node) =>
19
- context.report({ node, messageId: `${name}/error` });
20
- return {
21
- // FunctionDeclaration is only allowed when parent is Program, or parent is ExportNamedDeclaration, or parent is ExportDefaultDeclaration
22
- // function foo(){}
23
- "FunctionDeclaration[parent.type!='Program'][parent.type!='ExportNamedDeclaration'][parent.type!='ExportDefaultDeclaration']":
24
- handle,
25
- // FunctionExpression is only allowed when parent is MethodDefinition
26
- // function (){}
27
- "FunctionExpression[parent.type!='MethodDefinition']": handle,
28
- };
29
- },
30
- };
31
-
32
- export const noNestedFunction = { name, rule };
@@ -1,13 +0,0 @@
1
- import { test } from "@fenge/dev-utils";
2
- import { noRestrictedLoops } from "./no-restricted-loops.ts";
3
-
4
- const valid = ["for(const bar of foo) {}", "while(condition){}"];
5
-
6
- const invalid = [
7
- "for(let i = 0; i < foo.length; i++) {}",
8
- "for(const bar in foo) {}",
9
- "do{}while(condition)",
10
- "for await (const bar of foo()) {}",
11
- ];
12
-
13
- test({ valid, invalid, ...noRestrictedLoops });
@@ -1,30 +0,0 @@
1
- import type { Rule } from "eslint";
2
- import type { Node } from "estree";
3
- import { getRuleName } from "../utils.ts";
4
-
5
- // TODO: If https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2453 is accepted, migrate this rule to `eslint-plugin-unicorn`
6
- const name = getRuleName(import.meta.url);
7
- /**
8
- * Only allow `while` and `for-of` loops. `for`, `for-in`, `do-while` and `for-await-of` loops are disallowed.
9
- * Visit https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2453 for more details.
10
- */
11
- const rule: Rule.RuleModule = {
12
- meta: {
13
- docs: {
14
- description:
15
- "Only allow `while` and `for-of` loops. `for`, `for-in`, `do-while` and `for-await-of` loops are disallowed.",
16
- },
17
- messages: {
18
- [`${name}/error`]:
19
- "Only allow `while` and `for-of` loops. `for`, `for-in`, `do-while` and `for-await-of` loops are disallowed.",
20
- },
21
- },
22
- create: (context) => ({
23
- ":matches(ForStatement, ForInStatement, DoWhileStatement, ForOfStatement[await=true])":
24
- (node: Node) => {
25
- context.report({ node, messageId: `${name}/error` });
26
- },
27
- }),
28
- };
29
-
30
- export const noRestrictedLoops = { name, rule };
@@ -1,32 +0,0 @@
1
- import { test } from "@fenge/dev-utils";
2
- import { noTopLevelArrowFunction } from "./no-top-level-arrow-function.ts";
3
-
4
- const valid = [
5
- "function foo(){}",
6
- "const foo = function(){}",
7
- "const foo = function foo(){}",
8
- "if(true) const foo = () => {\n}",
9
-
10
- // allow one-line function
11
- "let foo = () => ''",
12
- "let foo = () => [\n]",
13
- "let foo = () => ({})",
14
- "const foo = () => ({})",
15
- "let foo; foo = () => ({})",
16
- "export const foo = () => ({})",
17
- "export let foo = () => ({})",
18
- "export default () => ({})",
19
- ];
20
-
21
- const invalid = [
22
- "let foo = () => {}",
23
- "const foo = () => {}",
24
- "let foo = () => {\n}",
25
- "const foo = () => {\n}",
26
- "let foo; foo = () => {\n}",
27
- "export const foo = () => {\n}",
28
- "export let foo = () => {\n}",
29
- "export default () => {\n}",
30
- ];
31
-
32
- test({ valid, invalid, ...noTopLevelArrowFunction });
@@ -1,35 +0,0 @@
1
- import type { Rule } from "eslint";
2
- import type { ArrowFunctionExpression } from "estree";
3
- import { getRuleName } from "../utils.ts";
4
-
5
- const name = getRuleName(import.meta.url);
6
- const rule: Rule.RuleModule = {
7
- meta: {
8
- docs: {
9
- description:
10
- "Top-level functions are expected to be function declarations instead of arrow functions.",
11
- },
12
- messages: {
13
- [`${name}/error`]:
14
- "Top-level functions are expected to be function declarations instead of arrow functions.",
15
- },
16
- },
17
- create: (context) => {
18
- const handle = (node: ArrowFunctionExpression) => {
19
- if (node.body.type === "BlockStatement") {
20
- context.report({ node, messageId: `${name}/error` });
21
- }
22
- };
23
- return {
24
- "VariableDeclaration[parent.type='Program'] > VariableDeclarator > ArrowFunctionExpression":
25
- handle,
26
- "ExpressionStatement[parent.type='Program'] > AssignmentExpression > ArrowFunctionExpression":
27
- handle,
28
- "ExportNamedDeclaration > VariableDeclaration > VariableDeclarator > ArrowFunctionExpression":
29
- handle,
30
- "ExportDefaultDeclaration > ArrowFunctionExpression": handle,
31
- };
32
- },
33
- };
34
-
35
- export const noTopLevelArrowFunction = { name, rule };
@@ -1,25 +0,0 @@
1
- import { test } from "@fenge/dev-utils";
2
- import { noUnnecessaryTemplateString } from "./no-unnecessary-template-string.ts";
3
-
4
- const valid = [
5
- "'abc'",
6
- '"def"',
7
- "`ab${cd}ef`",
8
- "`\n`",
9
- "`abc\n`",
10
- "`\nabc`",
11
- "`a\nbc`",
12
- ];
13
-
14
- const invalid = [
15
- // Currently, tagged template string should be reported as well.
16
- // Moving it to `valid` part is also reasonable.
17
- "outdent`foo`",
18
- "``",
19
- "`abc`",
20
- "`abc\\n`",
21
- "`\\nabc`",
22
- "`a\\nbc`",
23
- ];
24
-
25
- test({ valid, invalid, ...noUnnecessaryTemplateString });
@@ -1,29 +0,0 @@
1
- import type { Rule } from "eslint";
2
- import { getRuleName } from "../utils.ts";
3
-
4
- // TODO deprecate this rule if https://github.com/sindresorhus/eslint-plugin-unicorn/issues/71 is implemented.
5
- const name = getRuleName(import.meta.url);
6
- const rule: Rule.RuleModule = {
7
- meta: {
8
- docs: {
9
- description:
10
- "Disallow using template string when it's unnecessary. Use normal literal string expression instead.",
11
- },
12
- messages: {
13
- [`${name}/error`]:
14
- "Disallow using template string when it's unnecessary. Use normal literal string expression instead.",
15
- },
16
- },
17
- create: (context) => ({
18
- TemplateLiteral: (node) => {
19
- if (
20
- node.quasis.length === 1 &&
21
- node.expressions.length === 0 &&
22
- node.loc?.start.line === node.loc?.end.line
23
- ) {
24
- context.report({ node, messageId: `${name}/error` });
25
- }
26
- },
27
- }),
28
- };
29
- export const noUnnecessaryTemplateString = { name, rule };
package/src/utils.ts DELETED
@@ -1,7 +0,0 @@
1
- import path from "node:path";
2
- import { fileURLToPath } from "node:url";
3
-
4
- export function getRuleName(importMetaUrl: string) {
5
- // remove '.js' extension
6
- return path.basename(fileURLToPath(importMetaUrl)).slice(0, -3);
7
- }
package/tsconfig.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "../../tsconfig",
3
- "include": ["src"],
4
- "exclude": ["**/*.test.ts"]
5
- }