eslint-plugin-nima 0.0.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.
- package/README.md +1 -0
- package/dist/configs/recommended.d.ts +5 -0
- package/dist/configs/recommended.js +6 -0
- package/dist/configs/recommended.js.map +1 -0
- package/dist/constants/boolean-prefixes.d.ts +1 -0
- package/dist/constants/boolean-prefixes.js +12 -0
- package/dist/constants/boolean-prefixes.js.map +1 -0
- package/dist/constants/hooks.d.ts +2 -0
- package/dist/constants/hooks.js +26 -0
- package/dist/constants/hooks.js.map +1 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/rules/boolean-naming-convention.d.ts +9 -0
- package/dist/rules/boolean-naming-convention.js +307 -0
- package/dist/rules/boolean-naming-convention.js.map +1 -0
- package/dist/rules/no-handler-suffix.d.ts +3 -0
- package/dist/rules/no-handler-suffix.js +82 -0
- package/dist/rules/no-handler-suffix.js.map +1 -0
- package/dist/rules/no-objects-in-deps.d.ts +3 -0
- package/dist/rules/no-objects-in-deps.js +77 -0
- package/dist/rules/no-objects-in-deps.js.map +1 -0
- package/dist/rules/params-naming-convention.d.ts +8 -0
- package/dist/rules/params-naming-convention.js +92 -0
- package/dist/rules/params-naming-convention.js.map +1 -0
- package/dist/rules/prefer-arrow-functions.d.ts +10 -0
- package/dist/rules/prefer-arrow-functions.js +205 -0
- package/dist/rules/prefer-arrow-functions.js.map +1 -0
- package/dist/rules/prefer-react-fc.d.ts +6 -0
- package/dist/rules/prefer-react-fc.js +206 -0
- package/dist/rules/prefer-react-fc.js.map +1 -0
- package/dist/rules/prefer-react-with-hooks.d.ts +5 -0
- package/dist/rules/prefer-react-with-hooks.js +145 -0
- package/dist/rules/prefer-react-with-hooks.js.map +1 -0
- package/dist/rules/restrict-console-methods.d.ts +9 -0
- package/dist/rules/restrict-console-methods.js +68 -0
- package/dist/rules/restrict-console-methods.js.map +1 -0
- package/dist/utility/getFunctionName.d.ts +2 -0
- package/dist/utility/getFunctionName.js +33 -0
- package/dist/utility/getFunctionName.js.map +1 -0
- package/dist/utility/getType.d.ts +3 -0
- package/dist/utility/getType.js +21 -0
- package/dist/utility/getType.js.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
To be added...
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recommended.js","sourceRoot":"","sources":["../../src/configs/recommended.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,WAAW,GAEpB;IACF,8BAA8B,EAAE,OAAO;IACvC,4BAA4B,EAAE,MAAM;IACpC,qCAAqC,EAAE,OAAO;CAC/C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DEFAULT_PREFIXES: string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean-prefixes.js","sourceRoot":"","sources":["../../src/constants/boolean-prefixes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,IAAI;IACJ,KAAK;IACL,KAAK;IACL,QAAQ;IACR,MAAM;IACN,KAAK;IACL,MAAM;IACN,KAAK;IACL,IAAI;CACL,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const REACT_HOOKS = new Set([
|
|
2
|
+
"use",
|
|
3
|
+
"useCallback",
|
|
4
|
+
"useContext",
|
|
5
|
+
"useDebugValue",
|
|
6
|
+
"useDeferredValue",
|
|
7
|
+
"useEffect",
|
|
8
|
+
"useId",
|
|
9
|
+
"useImperativeHandle",
|
|
10
|
+
"useInsertionEffect",
|
|
11
|
+
"useLayoutEffect",
|
|
12
|
+
"useMemo",
|
|
13
|
+
"useReducer",
|
|
14
|
+
"useRef",
|
|
15
|
+
"useState",
|
|
16
|
+
"useSyncExternalStore",
|
|
17
|
+
"useTransition",
|
|
18
|
+
]);
|
|
19
|
+
export const HOOKS_WITH_DEPS = new Set([
|
|
20
|
+
"useCallback",
|
|
21
|
+
"useEffect",
|
|
22
|
+
"useInsertionEffect",
|
|
23
|
+
"useLayoutEffect",
|
|
24
|
+
"useMemo",
|
|
25
|
+
]);
|
|
26
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/constants/hooks.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IACjC,KAAK;IACL,aAAa;IACb,YAAY;IACZ,eAAe;IACf,kBAAkB;IAClB,WAAW;IACX,OAAO;IACP,qBAAqB;IACrB,oBAAoB;IACpB,iBAAiB;IACjB,SAAS;IACT,YAAY;IACZ,QAAQ;IACR,UAAU;IACV,sBAAsB;IACtB,eAAe;CAChB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IACrC,aAAa;IACb,WAAW;IACX,oBAAoB;IACpB,iBAAiB;IACjB,SAAS;CACV,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { RuleModule } from "@typescript-eslint/utils/ts-eslint";
|
|
2
|
+
import type { ESLint, Linter } from "eslint";
|
|
3
|
+
declare const rules: {
|
|
4
|
+
"boolean-naming-convention": RuleModule<"booleanFunctionName" | "booleanParameterName" | "booleanPropertyName" | "booleanVariableName", [{
|
|
5
|
+
allowedPrefixes: string[];
|
|
6
|
+
checkFunctions: boolean;
|
|
7
|
+
checkParameters: boolean;
|
|
8
|
+
checkProperties: boolean;
|
|
9
|
+
checkVariables: boolean;
|
|
10
|
+
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
11
|
+
"no-handler-suffix": RuleModule<"badHandleName", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
12
|
+
"no-objects-in-deps": RuleModule<"noObjects", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
13
|
+
"params-naming-convention": RuleModule<"useObjectParams", [{
|
|
14
|
+
allowedParameters: number;
|
|
15
|
+
ignore: string[];
|
|
16
|
+
ignoreFunctions: string[];
|
|
17
|
+
ignorePrefixes: string[];
|
|
18
|
+
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
19
|
+
"prefer-arrow-functions": RuleModule<"preferArrowFunction" | "preferArrowFunctionExpression" | "preferArrowMethod", [{
|
|
20
|
+
allowAsync: boolean;
|
|
21
|
+
allowConstructors: boolean;
|
|
22
|
+
allowFunctionDeclarations: boolean;
|
|
23
|
+
allowFunctionExpressions: boolean;
|
|
24
|
+
allowGenerators: boolean;
|
|
25
|
+
allowMethodDefinitions: boolean;
|
|
26
|
+
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
27
|
+
"prefer-react-fc": RuleModule<"addReactImport" | "requireReactFC", [{
|
|
28
|
+
allowArrowFunctions: boolean;
|
|
29
|
+
allowFunctionDeclarations: boolean;
|
|
30
|
+
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
31
|
+
"prefer-react-with-hooks": RuleModule<"preferReact" | "preferReactPrefix", [{
|
|
32
|
+
autoFix: boolean;
|
|
33
|
+
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
34
|
+
"restrict-console-methods": RuleModule<"noConsole", {
|
|
35
|
+
noConsoleError?: boolean;
|
|
36
|
+
noConsoleLog?: boolean;
|
|
37
|
+
noConsoleWarn?: boolean;
|
|
38
|
+
}[], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
39
|
+
};
|
|
40
|
+
export type RuleKey = keyof typeof rules;
|
|
41
|
+
interface Plugin extends Omit<ESLint.Plugin, "rules"> {
|
|
42
|
+
configs: {
|
|
43
|
+
"flat/recommended": Linter.Config;
|
|
44
|
+
recommended: ESLint.ConfigData;
|
|
45
|
+
};
|
|
46
|
+
rules: Record<RuleKey, RuleModule<any, any, any>>;
|
|
47
|
+
}
|
|
48
|
+
declare const plugin: {
|
|
49
|
+
configs: Plugin["configs"];
|
|
50
|
+
meta: {
|
|
51
|
+
name: string;
|
|
52
|
+
};
|
|
53
|
+
rules: {
|
|
54
|
+
"boolean-naming-convention": RuleModule<"booleanFunctionName" | "booleanParameterName" | "booleanPropertyName" | "booleanVariableName", [{
|
|
55
|
+
allowedPrefixes: string[];
|
|
56
|
+
checkFunctions: boolean;
|
|
57
|
+
checkParameters: boolean;
|
|
58
|
+
checkProperties: boolean;
|
|
59
|
+
checkVariables: boolean;
|
|
60
|
+
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
61
|
+
"no-handler-suffix": RuleModule<"badHandleName", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
62
|
+
"no-objects-in-deps": RuleModule<"noObjects", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
63
|
+
"params-naming-convention": RuleModule<"useObjectParams", [{
|
|
64
|
+
allowedParameters: number;
|
|
65
|
+
ignore: string[];
|
|
66
|
+
ignoreFunctions: string[];
|
|
67
|
+
ignorePrefixes: string[];
|
|
68
|
+
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
69
|
+
"prefer-arrow-functions": RuleModule<"preferArrowFunction" | "preferArrowFunctionExpression" | "preferArrowMethod", [{
|
|
70
|
+
allowAsync: boolean;
|
|
71
|
+
allowConstructors: boolean;
|
|
72
|
+
allowFunctionDeclarations: boolean;
|
|
73
|
+
allowFunctionExpressions: boolean;
|
|
74
|
+
allowGenerators: boolean;
|
|
75
|
+
allowMethodDefinitions: boolean;
|
|
76
|
+
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
77
|
+
"prefer-react-fc": RuleModule<"addReactImport" | "requireReactFC", [{
|
|
78
|
+
allowArrowFunctions: boolean;
|
|
79
|
+
allowFunctionDeclarations: boolean;
|
|
80
|
+
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
81
|
+
"prefer-react-with-hooks": RuleModule<"preferReact" | "preferReactPrefix", [{
|
|
82
|
+
autoFix: boolean;
|
|
83
|
+
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
84
|
+
"restrict-console-methods": RuleModule<"noConsole", {
|
|
85
|
+
noConsoleError?: boolean;
|
|
86
|
+
noConsoleLog?: boolean;
|
|
87
|
+
noConsoleWarn?: boolean;
|
|
88
|
+
}[], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
export default plugin;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { recommended } from "./configs/recommended.js";
|
|
2
|
+
import * as BooleanNamingConvention from "./rules/boolean-naming-convention.js";
|
|
3
|
+
import * as NoHandlerSuffix from "./rules/no-handler-suffix.js";
|
|
4
|
+
import * as NoObjectsInDeps from "./rules/no-objects-in-deps.js";
|
|
5
|
+
import * as ParamsNamingConvention from "./rules/params-naming-convention.js";
|
|
6
|
+
import * as PreferArrowFunctions from "./rules/prefer-arrow-functions.js";
|
|
7
|
+
import * as PreferReactFc from "./rules/prefer-react-fc.js";
|
|
8
|
+
import * as PreferReactWithHooks from "./rules/prefer-react-with-hooks.js";
|
|
9
|
+
import * as RestrictConsoleMethods from "./rules/restrict-console-methods.js";
|
|
10
|
+
const rules = {
|
|
11
|
+
[BooleanNamingConvention.name]: BooleanNamingConvention.rule,
|
|
12
|
+
[NoHandlerSuffix.name]: NoHandlerSuffix.rule,
|
|
13
|
+
[NoObjectsInDeps.name]: NoObjectsInDeps.rule,
|
|
14
|
+
[ParamsNamingConvention.name]: ParamsNamingConvention.rule,
|
|
15
|
+
[PreferArrowFunctions.name]: PreferArrowFunctions.rule,
|
|
16
|
+
[PreferReactFc.name]: PreferReactFc.rule,
|
|
17
|
+
[PreferReactWithHooks.name]: PreferReactWithHooks.rule,
|
|
18
|
+
[RestrictConsoleMethods.name]: RestrictConsoleMethods.rule,
|
|
19
|
+
};
|
|
20
|
+
const plugin = {
|
|
21
|
+
configs: {},
|
|
22
|
+
meta: {
|
|
23
|
+
name: "eslint-plugin-dragonswap",
|
|
24
|
+
},
|
|
25
|
+
rules,
|
|
26
|
+
};
|
|
27
|
+
Object.assign(plugin.configs, {
|
|
28
|
+
"flat/recommended": {
|
|
29
|
+
plugins: {
|
|
30
|
+
dragonswap: plugin,
|
|
31
|
+
},
|
|
32
|
+
rules: recommended,
|
|
33
|
+
},
|
|
34
|
+
recommended: {
|
|
35
|
+
plugins: ["dragonswap"],
|
|
36
|
+
rules: recommended,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
export default plugin;
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,uBAAuB,MAAM,sCAAsC,CAAC;AAChF,OAAO,KAAK,eAAe,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,eAAe,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,sBAAsB,MAAM,qCAAqC,CAAC;AAC9E,OAAO,KAAK,oBAAoB,MAAM,mCAAmC,CAAC;AAC1E,OAAO,KAAK,aAAa,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,oBAAoB,MAAM,oCAAoC,CAAC;AAC3E,OAAO,KAAK,sBAAsB,MAAM,qCAAqC,CAAC;AAE9E,MAAM,KAAK,GAAG;IACZ,CAAC,uBAAuB,CAAC,IAAI,CAAC,EAAE,uBAAuB,CAAC,IAAI;IAC5D,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,eAAe,CAAC,IAAI;IAC5C,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,eAAe,CAAC,IAAI;IAC5C,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,sBAAsB,CAAC,IAAI;IAC1D,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,oBAAoB,CAAC,IAAI;IACtD,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,IAAI;IACxC,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,oBAAoB,CAAC,IAAI;IACtD,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,sBAAsB,CAAC,IAAI;CAC3D,CAAC;AAYF,MAAM,MAAM,GAAG;IACb,OAAO,EAAE,EAAuB;IAEhC,IAAI,EAAE;QACJ,IAAI,EAAE,0BAA0B;KACjC;IAED,KAAK;CACN,CAAC;AAEF,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;IAC5B,kBAAkB,EAAE;QAClB,OAAO,EAAE;YACP,UAAU,EAAE,MAAM;SACnB;QACD,KAAK,EAAE,WAAW;KACnB;IACD,WAAW,EAAE;QACX,OAAO,EAAE,CAAC,YAAY,CAAC;QACvB,KAAK,EAAE,WAAW;KACnB;CACF,CAAC,CAAC;AAEH,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
export declare const name = "boolean-naming-convention";
|
|
3
|
+
export declare const rule: ESLintUtils.RuleModule<"booleanFunctionName" | "booleanParameterName" | "booleanPropertyName" | "booleanVariableName", [{
|
|
4
|
+
allowedPrefixes: string[];
|
|
5
|
+
checkFunctions: boolean;
|
|
6
|
+
checkParameters: boolean;
|
|
7
|
+
checkProperties: boolean;
|
|
8
|
+
checkVariables: boolean;
|
|
9
|
+
}], unknown, ESLintUtils.RuleListener>;
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { AST_NODE_TYPES, ESLintUtils, } from "@typescript-eslint/utils";
|
|
2
|
+
import { DEFAULT_PREFIXES } from "../constants/boolean-prefixes.js";
|
|
3
|
+
import { getType } from "../utility/getType.js";
|
|
4
|
+
export const name = "boolean-naming-convention";
|
|
5
|
+
export const rule = ESLintUtils.RuleCreator.withoutDocs({
|
|
6
|
+
create: (context, options) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const allowedPrefixes = options[0].allowedPrefixes;
|
|
9
|
+
const checkVariables = options[0].checkVariables;
|
|
10
|
+
const checkFunctions = options[0].checkFunctions;
|
|
11
|
+
const checkParameters = options[0].checkParameters;
|
|
12
|
+
const checkProperties = options[0].checkProperties;
|
|
13
|
+
const services = context.sourceCode.parserServices;
|
|
14
|
+
const checker = (_a = services === null || services === void 0 ? void 0 : services.program) === null || _a === void 0 ? void 0 : _a.getTypeChecker();
|
|
15
|
+
function hasValidBooleanPrefix(name) {
|
|
16
|
+
return allowedPrefixes === null || allowedPrefixes === void 0 ? void 0 : allowedPrefixes.some((prefix) => name.toLowerCase().startsWith(prefix.toLowerCase()));
|
|
17
|
+
}
|
|
18
|
+
function generateSuggestion(name) {
|
|
19
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
20
|
+
}
|
|
21
|
+
function isBooleanType(node) {
|
|
22
|
+
try {
|
|
23
|
+
const type = getType(context, node);
|
|
24
|
+
return type === "boolean" || type === "true" || type === "false";
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const isParamBoolean = (node) => {
|
|
31
|
+
var _a;
|
|
32
|
+
for (const param of node.params) {
|
|
33
|
+
if (param.type === AST_NODE_TYPES.Identifier &&
|
|
34
|
+
((_a = param.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation.type) ===
|
|
35
|
+
AST_NODE_TYPES.TSBooleanKeyword) {
|
|
36
|
+
const name = param.name;
|
|
37
|
+
if (!hasValidBooleanPrefix(name)) {
|
|
38
|
+
context.report({
|
|
39
|
+
data: {
|
|
40
|
+
name,
|
|
41
|
+
suggestion: generateSuggestion(name),
|
|
42
|
+
},
|
|
43
|
+
messageId: "booleanParameterName",
|
|
44
|
+
node: param,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
function functionReturnsBooleanType(node) {
|
|
51
|
+
var _a;
|
|
52
|
+
try {
|
|
53
|
+
const tsNode = (_a = services === null || services === void 0 ? void 0 : services.esTreeNodeToTSNodeMap) === null || _a === void 0 ? void 0 : _a.get(node);
|
|
54
|
+
if (!tsNode)
|
|
55
|
+
return false;
|
|
56
|
+
const signature = checker === null || checker === void 0 ? void 0 : checker.getSignatureFromDeclaration(tsNode);
|
|
57
|
+
if (signature && checker) {
|
|
58
|
+
const returnType = checker.getReturnTypeOfSignature(signature);
|
|
59
|
+
const returnTypeString = checker.typeToString(returnType);
|
|
60
|
+
return (returnTypeString === "boolean" ||
|
|
61
|
+
returnTypeString === "true" ||
|
|
62
|
+
returnTypeString === "false");
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
ArrowFunctionExpression(node) {
|
|
72
|
+
if (checkParameters) {
|
|
73
|
+
isParamBoolean(node);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
FunctionDeclaration: (node) => {
|
|
77
|
+
if (!checkFunctions)
|
|
78
|
+
return;
|
|
79
|
+
if (node.id && functionReturnsBooleanType(node)) {
|
|
80
|
+
const name = node.id.name;
|
|
81
|
+
if (!hasValidBooleanPrefix(name)) {
|
|
82
|
+
context.report({
|
|
83
|
+
data: {
|
|
84
|
+
name,
|
|
85
|
+
suggestion: generateSuggestion(name),
|
|
86
|
+
},
|
|
87
|
+
messageId: "booleanFunctionName",
|
|
88
|
+
node: node.id,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (checkParameters) {
|
|
93
|
+
isParamBoolean(node);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
FunctionExpression(node) {
|
|
97
|
+
if (checkParameters) {
|
|
98
|
+
isParamBoolean(node);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
ObjectExpression: (node) => {
|
|
102
|
+
if (!checkProperties)
|
|
103
|
+
return;
|
|
104
|
+
for (const prop of node.properties) {
|
|
105
|
+
if (prop.type === AST_NODE_TYPES.Property &&
|
|
106
|
+
prop.key.type === AST_NODE_TYPES.Identifier &&
|
|
107
|
+
!prop.computed &&
|
|
108
|
+
prop.value) {
|
|
109
|
+
if (isBooleanType(prop.value)) {
|
|
110
|
+
const name = prop.key.name;
|
|
111
|
+
if (!hasValidBooleanPrefix(name)) {
|
|
112
|
+
context.report({
|
|
113
|
+
data: {
|
|
114
|
+
name,
|
|
115
|
+
suggestion: generateSuggestion(name),
|
|
116
|
+
},
|
|
117
|
+
messageId: "booleanPropertyName",
|
|
118
|
+
node: prop.key,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
Property: (node) => {
|
|
126
|
+
var _a;
|
|
127
|
+
if (!checkParameters)
|
|
128
|
+
return;
|
|
129
|
+
if (node.key.type === AST_NODE_TYPES.Identifier &&
|
|
130
|
+
node.value.type === AST_NODE_TYPES.Identifier &&
|
|
131
|
+
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === AST_NODE_TYPES.ObjectPattern) {
|
|
132
|
+
let current = node.parent;
|
|
133
|
+
while (current && current.type !== AST_NODE_TYPES.Identifier) {
|
|
134
|
+
current = current.parent;
|
|
135
|
+
}
|
|
136
|
+
let param = node.parent;
|
|
137
|
+
while (param && param.parent) {
|
|
138
|
+
if (param.parent.type === AST_NODE_TYPES.ArrowFunctionExpression ||
|
|
139
|
+
param.parent.type === AST_NODE_TYPES.FunctionExpression ||
|
|
140
|
+
param.parent.type === AST_NODE_TYPES.FunctionDeclaration) {
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
param = param.parent;
|
|
144
|
+
}
|
|
145
|
+
if (param && "typeAnnotation" in param && param.typeAnnotation) {
|
|
146
|
+
const typeAnnotation = param.typeAnnotation;
|
|
147
|
+
if (typeAnnotation.typeAnnotation.type ===
|
|
148
|
+
AST_NODE_TYPES.TSTypeLiteral) {
|
|
149
|
+
const typeLiteral = typeAnnotation.typeAnnotation;
|
|
150
|
+
const propertyType = typeLiteral.members.find((member) => {
|
|
151
|
+
var _a, _b;
|
|
152
|
+
if (member.type === AST_NODE_TYPES.TSPropertySignature &&
|
|
153
|
+
((_a = member.key) === null || _a === void 0 ? void 0 : _a.type) === AST_NODE_TYPES.Identifier &&
|
|
154
|
+
member.key.name ===
|
|
155
|
+
node.key.name) {
|
|
156
|
+
return (((_b = member.typeAnnotation) === null || _b === void 0 ? void 0 : _b.typeAnnotation.type) ===
|
|
157
|
+
AST_NODE_TYPES.TSBooleanKeyword);
|
|
158
|
+
}
|
|
159
|
+
return false;
|
|
160
|
+
});
|
|
161
|
+
if (propertyType) {
|
|
162
|
+
const name = node.value.name;
|
|
163
|
+
if (!hasValidBooleanPrefix(name)) {
|
|
164
|
+
context.report({
|
|
165
|
+
data: {
|
|
166
|
+
name,
|
|
167
|
+
suggestion: generateSuggestion(name),
|
|
168
|
+
},
|
|
169
|
+
messageId: "booleanParameterName",
|
|
170
|
+
node: node.value,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
VariableDeclarator: (node) => {
|
|
179
|
+
var _a;
|
|
180
|
+
if (node.id.type === "ObjectPattern") {
|
|
181
|
+
if (!checkParameters)
|
|
182
|
+
return;
|
|
183
|
+
if (node.id.type === AST_NODE_TYPES.ObjectPattern && node.init) {
|
|
184
|
+
node.id.properties.forEach((prop) => {
|
|
185
|
+
var _a;
|
|
186
|
+
if (prop.type === AST_NODE_TYPES.Property &&
|
|
187
|
+
prop.key.type === AST_NODE_TYPES.Identifier &&
|
|
188
|
+
prop.value.type === AST_NODE_TYPES.Identifier) {
|
|
189
|
+
const valueName = prop.value.name;
|
|
190
|
+
try {
|
|
191
|
+
const tsNode = (_a = services === null || services === void 0 ? void 0 : services.esTreeNodeToTSNodeMap) === null || _a === void 0 ? void 0 : _a.get(prop.value);
|
|
192
|
+
if (tsNode && checker) {
|
|
193
|
+
const type = checker.getTypeAtLocation(tsNode);
|
|
194
|
+
const typeString = checker.typeToString(type);
|
|
195
|
+
if (typeString === "boolean" ||
|
|
196
|
+
typeString === "true" ||
|
|
197
|
+
typeString === "false") {
|
|
198
|
+
if (!hasValidBooleanPrefix(valueName)) {
|
|
199
|
+
context.report({
|
|
200
|
+
data: {
|
|
201
|
+
name: valueName,
|
|
202
|
+
suggestion: generateSuggestion(valueName),
|
|
203
|
+
},
|
|
204
|
+
messageId: "booleanVariableName",
|
|
205
|
+
node: prop.value,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch { }
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (!checkVariables)
|
|
217
|
+
return;
|
|
218
|
+
if (node.id.type === AST_NODE_TYPES.Identifier) {
|
|
219
|
+
if (((_a = node.id.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation.type) ===
|
|
220
|
+
AST_NODE_TYPES.TSBooleanKeyword) {
|
|
221
|
+
const name = node.id.name;
|
|
222
|
+
if (!hasValidBooleanPrefix(name)) {
|
|
223
|
+
context.report({
|
|
224
|
+
data: {
|
|
225
|
+
name,
|
|
226
|
+
suggestion: generateSuggestion(name),
|
|
227
|
+
},
|
|
228
|
+
messageId: "booleanVariableName",
|
|
229
|
+
node: node.id,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (node.init) {
|
|
235
|
+
if ((node.init.type === AST_NODE_TYPES.ArrowFunctionExpression ||
|
|
236
|
+
node.init.type === AST_NODE_TYPES.FunctionExpression) &&
|
|
237
|
+
functionReturnsBooleanType(node.init)) {
|
|
238
|
+
const name = node.id.name;
|
|
239
|
+
if (!hasValidBooleanPrefix(name)) {
|
|
240
|
+
context.report({
|
|
241
|
+
data: {
|
|
242
|
+
name,
|
|
243
|
+
suggestion: generateSuggestion(name),
|
|
244
|
+
},
|
|
245
|
+
messageId: "booleanFunctionName",
|
|
246
|
+
node: node.id,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else if (isBooleanType(node.init)) {
|
|
251
|
+
const name = node.id.name;
|
|
252
|
+
if (!hasValidBooleanPrefix(name)) {
|
|
253
|
+
context.report({
|
|
254
|
+
data: {
|
|
255
|
+
name,
|
|
256
|
+
suggestion: generateSuggestion(name),
|
|
257
|
+
},
|
|
258
|
+
messageId: "booleanVariableName",
|
|
259
|
+
node: node.id,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
},
|
|
268
|
+
defaultOptions: [
|
|
269
|
+
{
|
|
270
|
+
allowedPrefixes: DEFAULT_PREFIXES,
|
|
271
|
+
checkFunctions: true,
|
|
272
|
+
checkParameters: true,
|
|
273
|
+
checkProperties: true,
|
|
274
|
+
checkVariables: true,
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
meta: {
|
|
278
|
+
docs: {
|
|
279
|
+
description: "Enforces boolean variables to use appropriate prefixes (is, has, can, should, etc.)",
|
|
280
|
+
},
|
|
281
|
+
messages: {
|
|
282
|
+
booleanFunctionName: "NIMA: Function '{{name}}' returns a boolean, use a prefix like is{{suggestion}}}",
|
|
283
|
+
booleanParameterName: "NIMA: Boolean parameter '{{name}}' should use a prefix like is{{suggestion}}}",
|
|
284
|
+
booleanPropertyName: "NIMA: Boolean property '{{name}}' should use a prefix like is{{suggestion}}}",
|
|
285
|
+
booleanVariableName: "NIMA: Boolean variable '{{name}}' should use a prefix like is{{suggestion}}}",
|
|
286
|
+
},
|
|
287
|
+
schema: [
|
|
288
|
+
{
|
|
289
|
+
additionalProperties: false,
|
|
290
|
+
properties: {
|
|
291
|
+
allowedPrefixes: {
|
|
292
|
+
default: DEFAULT_PREFIXES,
|
|
293
|
+
items: { type: "string" },
|
|
294
|
+
type: "array",
|
|
295
|
+
},
|
|
296
|
+
checkFunctions: { default: true, type: "boolean" },
|
|
297
|
+
checkParameters: { default: true, type: "boolean" },
|
|
298
|
+
checkProperties: { default: true, type: "boolean" },
|
|
299
|
+
checkVariables: { default: true, type: "boolean" },
|
|
300
|
+
},
|
|
301
|
+
type: "object",
|
|
302
|
+
},
|
|
303
|
+
],
|
|
304
|
+
type: "suggestion",
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
//# sourceMappingURL=boolean-naming-convention.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean-naming-convention.js","sourceRoot":"","sources":["../../src/rules/boolean-naming-convention.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,WAAW,GAEZ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,MAAM,CAAC,MAAM,IAAI,GAAG,2BAA2B,CAAC;AAEhD,MAAM,CAAC,MAAM,IAAI,GAAG,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC;IACtD,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;;QAC3B,MAAM,eAAe,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC;QACnD,MAAM,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,cAAc,C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AAc,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE;iBACnD;gBACD,IAAI,EAAE,QAAQ;aACf;SACF;QACD,IAAI,EAAE,YAAY;KACnB;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
export const name = "no-handler-suffix";
|
|
3
|
+
export const rule = ESLintUtils.RuleCreator.withoutDocs({
|
|
4
|
+
create: (context) => {
|
|
5
|
+
function generateUniqueName(base, scope) {
|
|
6
|
+
let candidate = base;
|
|
7
|
+
let index = 2;
|
|
8
|
+
const existingNames = new Set(scope.variables.map((v) => v.name));
|
|
9
|
+
while (existingNames.has(candidate)) {
|
|
10
|
+
candidate = `${base}${index++}`;
|
|
11
|
+
}
|
|
12
|
+
return candidate;
|
|
13
|
+
}
|
|
14
|
+
function checkName(node, name) {
|
|
15
|
+
if (name === null || name === void 0 ? void 0 : name.toLowerCase().endsWith("handler")) {
|
|
16
|
+
const base = name.slice(0, -7);
|
|
17
|
+
const stripped = base.length === 0 ? "" : base[0].toUpperCase() + base.slice(1);
|
|
18
|
+
const suggestedBase = `handle${stripped}`;
|
|
19
|
+
const sourceCode = context.sourceCode;
|
|
20
|
+
const scope = sourceCode.getScope(node);
|
|
21
|
+
const uniqueName = generateUniqueName(suggestedBase, scope);
|
|
22
|
+
const variable = scope.set.get(name);
|
|
23
|
+
context.report({
|
|
24
|
+
data: {
|
|
25
|
+
fnWithGoodName: uniqueName,
|
|
26
|
+
},
|
|
27
|
+
fix(fixer) {
|
|
28
|
+
const fixes = [fixer.replaceText(node, uniqueName)];
|
|
29
|
+
if (variable) {
|
|
30
|
+
for (const ref of variable.references) {
|
|
31
|
+
if (ref.identifier !== node) {
|
|
32
|
+
fixes.push(fixer.replaceText(ref.identifier, uniqueName));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return fixes;
|
|
37
|
+
},
|
|
38
|
+
messageId: "badHandleName",
|
|
39
|
+
node,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
ArrowFunctionExpression(node) {
|
|
45
|
+
const parent = node.parent;
|
|
46
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === "VariableDeclarator" &&
|
|
47
|
+
parent.id.type === "Identifier") {
|
|
48
|
+
checkName(parent.id, parent.id.name);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
FunctionDeclaration(node) {
|
|
52
|
+
var _a;
|
|
53
|
+
if (node.id) {
|
|
54
|
+
checkName(node.id, (_a = node.id) === null || _a === void 0 ? void 0 : _a.name);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
FunctionExpression(node) {
|
|
58
|
+
const parent = node.parent;
|
|
59
|
+
if (node.id) {
|
|
60
|
+
checkName(node.id, node.id.name);
|
|
61
|
+
}
|
|
62
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === "VariableDeclarator" &&
|
|
63
|
+
parent.id.type === "Identifier") {
|
|
64
|
+
checkName(parent.id, parent.id.name);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
defaultOptions: [],
|
|
70
|
+
meta: {
|
|
71
|
+
docs: {
|
|
72
|
+
description: "Suggests to use handleFn instead of fnHandler",
|
|
73
|
+
},
|
|
74
|
+
fixable: "code",
|
|
75
|
+
messages: {
|
|
76
|
+
badHandleName: "NIMA: You shouldn't use the handler suffix, use the handle prefix instead ({{ fnWithGoodName }})",
|
|
77
|
+
},
|
|
78
|
+
schema: [],
|
|
79
|
+
type: "suggestion",
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
//# sourceMappingURL=no-handler-suffix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-handler-suffix.js","sourceRoot":"","sources":["../../src/rules/no-handler-suffix.ts"],"names":[],"mappings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