@blumintinc/eslint-plugin-blumint 0.1.23 → 1.0.2

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 (52) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +277 -55
  3. package/assets/logo.svg +26 -0
  4. package/jest.config.js +13 -0
  5. package/package.json +74 -25
  6. package/plugin/README.md +80 -0
  7. package/{docs → plugin/docs}/rules/class-methods-read-top-to-bottom.md +3 -1
  8. package/{docs → plugin/docs}/rules/dynamic-https-errors.md +1 -1
  9. package/{docs → plugin/docs}/rules/require-memo.md +9 -2
  10. package/plugin/package-lock.json +7662 -0
  11. package/plugin/package.json +45 -0
  12. package/tsconfig.json +79 -0
  13. package/lib/index.js +0 -69
  14. package/lib/rules/array-methods-this-context.js +0 -64
  15. package/lib/rules/class-methods-read-top-to-bottom.js +0 -72
  16. package/lib/rules/dynamic-https-errors.js +0 -57
  17. package/lib/rules/export-if-in-doubt.js +0 -69
  18. package/lib/rules/extract-global-constants.js +0 -63
  19. package/lib/rules/generic-starts-with-t.js +0 -35
  20. package/lib/rules/no-async-array-filter.js +0 -40
  21. package/lib/rules/no-async-foreach.js +0 -37
  22. package/lib/rules/no-conditional-literals-in-jsx.js +0 -61
  23. package/lib/rules/no-filter-without-return.js +0 -41
  24. package/lib/rules/no-misused-switch-case.js +0 -35
  25. package/lib/rules/no-unpinned-dependencies.js +0 -65
  26. package/lib/rules/no-useless-fragment.js +0 -46
  27. package/lib/rules/prefer-fragment-shorthand.js +0 -40
  28. package/lib/rules/prefer-type-over-interface.js +0 -45
  29. package/lib/rules/require-memo.js +0 -134
  30. package/lib/utils/ASTHelpers.js +0 -336
  31. package/lib/utils/ClassGraphBuilder.js +0 -80
  32. package/lib/utils/ClassGraphSorter.js +0 -99
  33. package/lib/utils/createRule.js +0 -6
  34. package/lib/utils/graph/ClassGraphBuilder.js +0 -80
  35. package/lib/utils/graph/ClassGraphSorter.js +0 -10
  36. package/lib/utils/graph/ClassGraphSorterReadability.js +0 -94
  37. package/lib/utils/graph.js +0 -109
  38. package/lib/utils/ruleTester.js +0 -23
  39. package/lib/utils/testClass.js +0 -45
  40. /package/{docs → plugin/docs}/rules/array-methods-this-context.md +0 -0
  41. /package/{docs → plugin/docs}/rules/export-if-in-doubt.md +0 -0
  42. /package/{docs → plugin/docs}/rules/extract-global-constants.md +0 -0
  43. /package/{docs → plugin/docs}/rules/generic-starts-with-t.md +0 -0
  44. /package/{docs → plugin/docs}/rules/no-async-array-filter.md +0 -0
  45. /package/{docs → plugin/docs}/rules/no-async-foreach.md +0 -0
  46. /package/{docs → plugin/docs}/rules/no-conditional-literals-in-jsx.md +0 -0
  47. /package/{docs → plugin/docs}/rules/no-filter-without-return.md +0 -0
  48. /package/{docs → plugin/docs}/rules/no-misused-switch-case.md +0 -0
  49. /package/{docs → plugin/docs}/rules/no-unpinned-dependencies.md +0 -0
  50. /package/{docs → plugin/docs}/rules/no-useless-fragment.md +0 -0
  51. /package/{docs → plugin/docs}/rules/prefer-fragment-shorthand.md +0 -0
  52. /package/{docs → plugin/docs}/rules/prefer-type-over-interface.md +0 -0
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@blumintinc/eslint-plugin-blumint",
3
+ "version": "0.1.24",
4
+ "description": "Custom eslint rules for use at BluMint",
5
+ "keywords": [
6
+ "eslint",
7
+ "eslintplugin",
8
+ "eslint-plugin"
9
+ ],
10
+ "author": "Brodie McGuire",
11
+ "main": "./lib/index.js",
12
+ "exports": "./lib/index.js",
13
+ "scripts": {
14
+ "lint": "npm-run-all \"lint:*\"",
15
+ "lint:eslint-docs": "npm-run-all \"update:eslint-docs -- --check\"",
16
+ "lint:js": "eslint ./src",
17
+ "test": "jest",
18
+ "docs": "./scripts/make-docs.sh && npm run update:eslint-docs",
19
+ "update:eslint-docs": "eslint-doc-generator"
20
+ },
21
+ "dependencies": {
22
+ "requireindex": "1.2.0"
23
+ },
24
+ "devDependencies": {
25
+ "@types/eslint": "8.37.0",
26
+ "@typescript-eslint/utils": "5.59.6",
27
+ "eslint": "8.19.0",
28
+ "eslint-doc-generator": "1.0.0",
29
+ "eslint-import-resolver-typescript": "3.5.5",
30
+ "eslint-plugin-eslint-plugin": "5.0.0",
31
+ "@blumintinc/eslint-plugin-blumint": "file:./",
32
+ "eslint-plugin-node": "11.1.0",
33
+ "jest": "29.3.1",
34
+ "jsonc-eslint-parser": "2.3.0",
35
+ "npm-run-all": "4.1.5",
36
+ "ts-jest": "29.0.5"
37
+ },
38
+ "engines": {
39
+ "node": "^20.0.0"
40
+ },
41
+ "peerDependencies": {
42
+ "eslint": ">=7"
43
+ },
44
+ "license": "ISC"
45
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2015" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
4
+ "module": "ESNext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
5
+ "lib": [
6
+ "esnext",
7
+ "DOM",
8
+ "DOM.Iterable",
9
+ "WebWorker",
10
+ ],
11
+ "resolveJsonModule": true,
12
+ "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */
13
+ "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
14
+ "declaration": true /* Generates corresponding '.d.ts' file. */,
15
+ "sourceMap": true, /* Generates corresponding '.map' file. */
16
+ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
17
+ // "outFile": "./", /* Concatenate and emit output to single file. */
18
+ // "outDir": "./lib/esm" /* Redirect output structure to the directory. */,
19
+ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
20
+ // "composite": true, /* Enable project compilation */
21
+ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
22
+ "removeComments": true /* Do not emit comments to output. */,
23
+ "noEmit": true, /* Do not emit outputs. */ // "importHelpers": true, /* Import emit helpers from 'tslib'. */
24
+ "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
25
+ "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ /* Strict Type-Checking Options */
26
+ "strict": true /* Enable all strict type-checking options. */,
27
+ "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
28
+ "strictNullChecks": true /* Enable strict null checks. */,
29
+ // "strictFunctionTypes": true, /* Enable strict checking of function types. */
30
+ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
31
+ "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
32
+ // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
33
+ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
34
+ /* Additional Checks */
35
+ "noUnusedLocals": true /* Report errors on unused locals. */,
36
+ "noUnusedParameters": true /* Report errors on unused parameters. */,
37
+ "noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
38
+ "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
39
+ /* Module Resolution Options */
40
+ "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
41
+ "baseUrl": ".", /* Base directory to resolve non-absolute module names. */ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
42
+ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
43
+ "typeRoots": [
44
+ "node_modules/@types"
45
+ ], /* List of folders to include type definitions from. */
46
+ "types": [
47
+ "node",
48
+ "jest"
49
+ ], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
50
+ "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
51
+ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
52
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
53
+ /* Source Map Options */
54
+ // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
55
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
56
+ // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
57
+ // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
58
+ /* Experimental Options */
59
+ "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
60
+ "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ /* Advanced Options */
61
+ "skipLibCheck": true /* Skip type checking of declaration files. */,
62
+ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
63
+ "incremental": true
64
+ // "incremental": true /* Disabled to prevent CI build errors */
65
+ },
66
+ "incremental": true,
67
+ "compileOnSave": true,
68
+ "include": [
69
+ "*.js",
70
+ "**/*.test.ts",
71
+ "**/*.ts",
72
+ "**/*.js",
73
+ "**/*.tsx",
74
+ "types.d.ts"
75
+ ],
76
+ "exclude": [
77
+ "node_modules",
78
+ ]
79
+ }
package/lib/index.js DELETED
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const array_methods_this_context_1 = require("./rules/array-methods-this-context");
4
- const class_methods_read_top_to_bottom_1 = require("./rules/class-methods-read-top-to-bottom");
5
- const dynamic_https_errors_1 = require("./rules/dynamic-https-errors");
6
- const export_if_in_doubt_1 = require("./rules/export-if-in-doubt");
7
- const extract_global_constants_1 = require("./rules/extract-global-constants");
8
- const generic_starts_with_t_1 = require("./rules/generic-starts-with-t");
9
- const no_async_array_filter_1 = require("./rules/no-async-array-filter");
10
- const no_async_foreach_1 = require("./rules/no-async-foreach");
11
- const no_conditional_literals_in_jsx_1 = require("./rules/no-conditional-literals-in-jsx");
12
- const no_filter_without_return_1 = require("./rules/no-filter-without-return");
13
- const no_misused_switch_case_1 = require("./rules/no-misused-switch-case");
14
- const no_unpinned_dependencies_1 = require("./rules/no-unpinned-dependencies");
15
- const no_useless_fragment_1 = require("./rules/no-useless-fragment");
16
- const prefer_fragment_shorthand_1 = require("./rules/prefer-fragment-shorthand");
17
- const prefer_type_over_interface_1 = require("./rules/prefer-type-over-interface");
18
- const require_memo_1 = require("./rules/require-memo");
19
- module.exports = {
20
- meta: {
21
- name: '@blumintinc/eslint-plugin-blumint',
22
- version: '0.1.23',
23
- },
24
- parseOptions: {
25
- ecmaVersion: 2020,
26
- },
27
- configs: {
28
- recommended: {
29
- plugins: ['@blumintinc/blumint'],
30
- rules: {
31
- '@blumintinc/blumint/array-methods-this-context': 'warn',
32
- '@blumintinc/blumint/class-methods-read-top-to-bottom': 'warn',
33
- '@blumintinc/blumint/dynamic-https-errors': 'warn',
34
- // '@blumintinc/blumint/export-if-in-doubt': 'warn',
35
- // '@blumintinc/blumint/extract-global-constants': 'warn',
36
- '@blumintinc/blumint/generic-starts-with-t': 'warn',
37
- '@blumintinc/blumint/no-async-array-filter': 'error',
38
- '@blumintinc/blumint/no-async-foreach': 'error',
39
- '@blumintinc/blumint/no-conditional-literals-in-jsx': 'error',
40
- '@blumintinc/blumint/no-filter-without-return': 'error',
41
- '@blumintinc/blumint/no-misused-switch-case': 'error',
42
- '@blumintinc/blumint/no-unpinned-dependencies': 'error',
43
- '@blumintinc/blumint/no-useless-fragment': 'warn',
44
- '@blumintinc/blumint/prefer-fragment-shorthand': 'warn',
45
- '@blumintinc/blumint/prefer-type-over-interface': 'warn',
46
- '@blumintinc/blumint/require-memo': 'error',
47
- },
48
- },
49
- },
50
- rules: {
51
- 'array-methods-this-context': array_methods_this_context_1.arrayMethodsThisContext,
52
- 'class-methods-read-top-to-bottom': class_methods_read_top_to_bottom_1.classMethodsReadTopToBottom,
53
- 'dynamic-https-errors': dynamic_https_errors_1.dynamicHttpsErrors,
54
- 'export-if-in-doubt': export_if_in_doubt_1.exportIfInDoubt,
55
- 'extract-global-constants': extract_global_constants_1.extractGlobalConstants,
56
- 'generic-starts-with-t': generic_starts_with_t_1.genericStartsWithT,
57
- 'no-async-array-filter': no_async_array_filter_1.noAsyncArrayFilter,
58
- 'no-async-foreach': no_async_foreach_1.noAsyncForEach,
59
- 'no-conditional-literals-in-jsx': no_conditional_literals_in_jsx_1.noConditionalLiteralsInJsx,
60
- 'no-filter-without-return': no_filter_without_return_1.noFilterWithoutReturn,
61
- 'no-misused-switch-case': no_misused_switch_case_1.noMisusedSwitchCase,
62
- 'no-unpinned-dependencies': no_unpinned_dependencies_1.noUnpinnedDependencies,
63
- 'no-useless-fragment': no_useless_fragment_1.noUselessFragment,
64
- 'prefer-fragment-shorthand': prefer_fragment_shorthand_1.preferFragmentShorthand,
65
- 'prefer-type-over-interface': prefer_type_over_interface_1.preferTypeOverInterface,
66
- 'require-memo': require_memo_1.requireMemo,
67
- },
68
- };
69
- //# sourceMappingURL=index.js.map
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.arrayMethodsThisContext = exports.ARRAY_METHODS = void 0;
4
- const createRule_1 = require("../utils/createRule");
5
- exports.ARRAY_METHODS = [
6
- 'map',
7
- 'filter',
8
- 'forEach',
9
- 'reduce',
10
- 'some',
11
- 'every',
12
- ];
13
- exports.arrayMethodsThisContext = (0, createRule_1.createRule)({
14
- create(context) {
15
- return {
16
- CallExpression(node) {
17
- // Array method called with a class method reference
18
- if (node.callee.type === 'MemberExpression' &&
19
- node.callee.property.type === 'Identifier' &&
20
- exports.ARRAY_METHODS.includes(node.callee.property.name) &&
21
- node.arguments.length > 0 &&
22
- node.arguments[0].type === 'MemberExpression' &&
23
- node.arguments[0].object.type === 'ThisExpression') {
24
- context.report({
25
- node: node.arguments[0],
26
- messageId: 'unexpected',
27
- });
28
- }
29
- // Function expression bound to `this` in array method
30
- else if (node.callee.type === 'MemberExpression' &&
31
- node.callee.property.type === 'Identifier' &&
32
- exports.ARRAY_METHODS.includes(node.callee.property.name) &&
33
- node.arguments.length > 0 &&
34
- node.arguments[0].type === 'CallExpression' &&
35
- node.arguments[0].callee.type === 'MemberExpression' &&
36
- node.arguments[0].callee.object.type === 'FunctionExpression' &&
37
- node.arguments[0].callee.property.type === 'Identifier' &&
38
- node.arguments[0].callee.property.name === 'bind' &&
39
- node.arguments[0].arguments.length > 0 &&
40
- node.arguments[0].arguments[0].type === 'ThisExpression') {
41
- context.report({
42
- node: node.arguments[0],
43
- messageId: 'preferArrow',
44
- });
45
- }
46
- },
47
- };
48
- },
49
- name: 'array-methods-this-context',
50
- meta: {
51
- type: 'problem',
52
- docs: {
53
- description: 'Prevent misuse of Array methods in OOP',
54
- recommended: 'error',
55
- },
56
- schema: [],
57
- messages: {
58
- unexpected: 'Use an arrow function to preserve "this" context.',
59
- preferArrow: 'Use an arrow function instead of binding this.',
60
- },
61
- },
62
- defaultOptions: [],
63
- });
64
- //# sourceMappingURL=array-methods-this-context.js.map
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.classMethodsReadTopToBottom = void 0;
4
- const createRule_1 = require("../utils/createRule");
5
- const ClassGraphBuilder_1 = require("../utils/graph/ClassGraphBuilder");
6
- function getMemberName(member) {
7
- if (member.type === 'MethodDefinition' ||
8
- member.type === 'PropertyDefinition') {
9
- return member.key.type === 'Identifier' ? member.key.name : null;
10
- }
11
- return null;
12
- }
13
- exports.classMethodsReadTopToBottom = (0, createRule_1.createRule)({
14
- name: 'class-methods-read-top-to-bottom',
15
- meta: {
16
- type: 'suggestion',
17
- docs: {
18
- description: 'Ensures classes read linearly from top to bottom.',
19
- recommended: 'warn',
20
- },
21
- schema: [],
22
- messages: {
23
- classMethodsReadTopToBottom: 'Methods should be ordered for top-down readability.',
24
- },
25
- fixable: 'code', // To allow ESLint to autofix issues.
26
- },
27
- defaultOptions: [],
28
- create(context) {
29
- let className;
30
- return {
31
- ClassDeclaration(node) {
32
- className = node.id?.name || '';
33
- },
34
- 'ClassBody:exit'(node) {
35
- const graphBuilder = new ClassGraphBuilder_1.ClassGraphBuilder(className, node);
36
- const sortedOrder = graphBuilder.memberNamesSorted;
37
- const actualOrder = node.body
38
- .map((member) => member.type === 'MethodDefinition' ||
39
- member.type === 'PropertyDefinition'
40
- ? member.key.name
41
- : null)
42
- .filter(Boolean);
43
- for (let i = 0; i < actualOrder.length; i++) {
44
- if (actualOrder[i] !== sortedOrder[i]) {
45
- const sourceCode = context.getSourceCode();
46
- const newClassBody = sortedOrder
47
- .map((n) => {
48
- // Fetch the actual AST node corresponding to the name
49
- const memberNode = node.body.find((member) => getMemberName(member) === n);
50
- const comments = sourceCode.getCommentsBefore(memberNode);
51
- memberNode.range = [
52
- Math.min(memberNode.range[0], Math.min(...comments.map((comment) => comment.range[0]))),
53
- Math.max(memberNode.range[1], Math.max(...comments.map((comment) => comment.range[1]))),
54
- ];
55
- return sourceCode.getText(memberNode);
56
- })
57
- .join('\n');
58
- return context.report({
59
- node,
60
- messageId: 'classMethodsReadTopToBottom',
61
- fix(fixer) {
62
- return fixer.replaceTextRange([node.range[0] + 1, node.range[1] - 1], // Exclude the curly braces
63
- newClassBody);
64
- },
65
- });
66
- }
67
- }
68
- },
69
- };
70
- },
71
- });
72
- //# sourceMappingURL=class-methods-read-top-to-bottom.js.map
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dynamicHttpsErrors = void 0;
4
- /* eslint-disable @blumintinc/blumint/extract-global-constants */
5
- const createRule_1 = require("../utils/createRule");
6
- const isHttpsErrorCall = (callee) => {
7
- if (callee.type === 'MemberExpression') {
8
- return (callee.object.type === 'Identifier' &&
9
- callee.object.name === 'https' &&
10
- callee.property.type === 'Identifier' &&
11
- callee.property.name === 'HttpsError');
12
- }
13
- else if (callee.type === 'Identifier') {
14
- return callee.name === 'HttpsError';
15
- }
16
- return false;
17
- };
18
- exports.dynamicHttpsErrors = (0, createRule_1.createRule)({
19
- name: 'dynamic-https-errors',
20
- meta: {
21
- type: 'suggestion',
22
- docs: {
23
- description: 'Dynamic error details should only be in the third argument of the HttpsError constructor. The second argument is hashed to produce a unique id.',
24
- recommended: 'warn',
25
- },
26
- schema: [],
27
- messages: {
28
- dynamicHttpsErrors: 'Found dynamic error details in the second argument of the HttpsError constructor - the "message" field. This field is hashed to produce a unique id for error monitoring. Move any dynamic details to the third argument - the "details" field - to preserve the unique id and to monitor the error correctly.',
29
- },
30
- },
31
- defaultOptions: [],
32
- create(context) {
33
- const checkForHttpsError = (node) => {
34
- const callee = node.callee;
35
- if (isHttpsErrorCall(callee)) {
36
- const secondArg = node.arguments[1];
37
- if (secondArg && secondArg.type === 'TemplateLiteral') {
38
- if (secondArg.expressions.length > 0) {
39
- context.report({
40
- node: secondArg,
41
- messageId: 'dynamicHttpsErrors',
42
- });
43
- }
44
- }
45
- }
46
- };
47
- return {
48
- NewExpression(node) {
49
- return checkForHttpsError(node);
50
- },
51
- CallExpression(node) {
52
- return checkForHttpsError(node);
53
- },
54
- };
55
- },
56
- });
57
- //# sourceMappingURL=dynamic-https-errors.js.map
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exportIfInDoubt = void 0;
4
- /* eslint-disable @blumintinc/blumint/extract-global-constants */
5
- // import { ASTHelpers } from '../utils/ASTHelpers';
6
- const createRule_1 = require("../utils/createRule");
7
- exports.exportIfInDoubt = (0, createRule_1.createRule)({
8
- name: 'export-if-in-doubt',
9
- meta: {
10
- type: 'suggestion',
11
- docs: {
12
- description: 'All top-level const definitions, type definitions, and functions should be exported',
13
- recommended: 'warn',
14
- },
15
- schema: [],
16
- messages: {
17
- exportIfInDoubt: 'Top-level const definitions, type definitions, and functions should be exported.',
18
- },
19
- },
20
- defaultOptions: [],
21
- create(context) {
22
- // List of top-level declarations
23
- // List of exported identifiers
24
- const topLevelDeclarations = [];
25
- const exportedIdentifiers = [];
26
- return {
27
- 'Program > VariableDeclaration > VariableDeclarator, Program > FunctionDeclaration, Program > TSTypeAliasDeclaration'(node) {
28
- topLevelDeclarations.push(node);
29
- },
30
- ExportNamedDeclaration: (node) => {
31
- if (node.specifiers) {
32
- node.specifiers.forEach((specifier) => {
33
- if (specifier.type === 'ExportSpecifier') {
34
- // Handle both normal and default export
35
- const exportedName = specifier.exported.name;
36
- if (!exportedIdentifiers.includes(exportedName)) {
37
- exportedIdentifiers.push(exportedName);
38
- }
39
- // If the specifier is a default export
40
- if (specifier.local.name !== exportedName) {
41
- const localName = specifier.local.name;
42
- if (!exportedIdentifiers.includes(localName)) {
43
- exportedIdentifiers.push(localName);
44
- }
45
- }
46
- }
47
- });
48
- }
49
- },
50
- 'Program:exit': () => {
51
- topLevelDeclarations.forEach((node) => {
52
- if ('id' in node &&
53
- node.id &&
54
- (node.type === 'VariableDeclarator' ||
55
- node.type === 'FunctionDeclaration' ||
56
- node.type === 'TSTypeAliasDeclaration') &&
57
- node.id.type === 'Identifier' &&
58
- !exportedIdentifiers.includes(node.id.name)) {
59
- context.report({
60
- node,
61
- messageId: 'exportIfInDoubt',
62
- });
63
- }
64
- });
65
- },
66
- };
67
- },
68
- });
69
- //# sourceMappingURL=export-if-in-doubt.js.map
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractGlobalConstants = void 0;
4
- const ASTHelpers_1 = require("../utils/ASTHelpers");
5
- const createRule_1 = require("../utils/createRule");
6
- exports.extractGlobalConstants = (0, createRule_1.createRule)({
7
- create(context) {
8
- return {
9
- VariableDeclaration(node) {
10
- if (node.kind !== 'const') {
11
- return;
12
- }
13
- const scope = context.getScope();
14
- const hasDependencies = node.declarations.some((declaration) => declaration.init &&
15
- ASTHelpers_1.ASTHelpers.declarationIncludesIdentifier(declaration.init));
16
- if (!hasDependencies &&
17
- (scope.type === 'function' || scope.type === 'block')) {
18
- const constName = node.declarations[0].id.name;
19
- context.report({
20
- node,
21
- messageId: 'extractGlobalConstants',
22
- data: {
23
- declarationName: constName,
24
- },
25
- });
26
- }
27
- },
28
- FunctionDeclaration(node) {
29
- if (node.parent &&
30
- (node.parent.type === 'FunctionDeclaration' ||
31
- node.parent.type === 'FunctionExpression' ||
32
- node.parent.type === 'ArrowFunctionExpression')) {
33
- const scope = context.getScope();
34
- const hasDependencies = ASTHelpers_1.ASTHelpers.blockIncludesIdentifier(node.body);
35
- if (!hasDependencies && scope.type === 'function') {
36
- const funcName = node.id.name;
37
- context.report({
38
- node,
39
- messageId: 'extractGlobalConstants',
40
- data: {
41
- declarationName: funcName,
42
- },
43
- });
44
- }
45
- }
46
- },
47
- };
48
- },
49
- name: 'extract-global-constants',
50
- meta: {
51
- type: 'suggestion',
52
- docs: {
53
- description: 'Extract constants/functions to the global scope when possible',
54
- recommended: 'error',
55
- },
56
- schema: [],
57
- messages: {
58
- extractGlobalConstants: 'Move this declaration {{ declarationName }} to the global scope and rename it to UPPER_SNAKE_CASE if necessary.',
59
- },
60
- },
61
- defaultOptions: [],
62
- });
63
- //# sourceMappingURL=extract-global-constants.js.map
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.genericStartsWithT = void 0;
4
- const createRule_1 = require("../utils/createRule");
5
- exports.genericStartsWithT = (0, createRule_1.createRule)({
6
- create(context) {
7
- return {
8
- TSTypeParameterDeclaration(node) {
9
- for (const param of node.params) {
10
- if (typeof param.name.name === 'string' &&
11
- param.name.name[0] !== 'T') {
12
- context.report({
13
- node: param,
14
- messageId: 'genericStartsWithT',
15
- });
16
- }
17
- }
18
- },
19
- };
20
- },
21
- name: 'generic-starts-with-t',
22
- meta: {
23
- type: 'suggestion',
24
- docs: {
25
- description: 'Enforce TypeScript generic types to start with T',
26
- recommended: 'error',
27
- },
28
- schema: [],
29
- messages: {
30
- genericStartsWithT: 'Generic type parameter should start with T.',
31
- },
32
- },
33
- defaultOptions: [],
34
- });
35
- //# sourceMappingURL=generic-starts-with-t.js.map
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noAsyncArrayFilter = void 0;
4
- const createRule_1 = require("../utils/createRule");
5
- exports.noAsyncArrayFilter = (0, createRule_1.createRule)({
6
- create(context) {
7
- return {
8
- CallExpression(node) {
9
- if (node.callee.type === 'MemberExpression' &&
10
- node.callee.property.type === 'Identifier' &&
11
- node.callee.property.name === 'filter' &&
12
- node.arguments.length > 0) {
13
- const callback = node.arguments[0];
14
- if ((callback.type === 'FunctionExpression' ||
15
- callback.type === 'ArrowFunctionExpression') &&
16
- callback.async === true) {
17
- context.report({
18
- node: callback,
19
- messageId: 'unexpected',
20
- });
21
- }
22
- }
23
- },
24
- };
25
- },
26
- name: 'no-async-array-filter',
27
- meta: {
28
- type: 'problem',
29
- docs: {
30
- description: 'Disallow async callbacks for Array.filter',
31
- recommended: 'error',
32
- },
33
- schema: [],
34
- messages: {
35
- unexpected: 'Async array filter is dangerous as a Promise object will always be truthy. You should move the asynchronous logic elsewhere.',
36
- },
37
- },
38
- defaultOptions: [],
39
- });
40
- //# sourceMappingURL=no-async-array-filter.js.map
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noAsyncForEach = void 0;
4
- exports.noAsyncForEach = {
5
- create(context) {
6
- return {
7
- CallExpression(node) {
8
- const callee = node.callee;
9
- if (callee.type === 'MemberExpression' &&
10
- callee.property.type === 'Identifier' &&
11
- callee.property.name === 'forEach' &&
12
- node.arguments[0] &&
13
- (node.arguments[0].type === 'ArrowFunctionExpression' ||
14
- node.arguments[0].type === 'FunctionExpression') &&
15
- node.arguments[0].async) {
16
- context.report({
17
- node,
18
- messageId: 'noAsyncForEach',
19
- });
20
- }
21
- },
22
- };
23
- },
24
- meta: {
25
- type: 'problem',
26
- docs: {
27
- description: 'Disallow Array.forEach with an async callback function',
28
- recommended: 'error',
29
- },
30
- messages: {
31
- noAsyncForEach: 'Do not use async function as callback in Array.forEach. Use a standard for loop for sequential execution or Promise.all for concurrent execution.',
32
- },
33
- schema: [],
34
- },
35
- defaultOptions: [],
36
- };
37
- //# sourceMappingURL=no-async-foreach.js.map