@e18e/eslint-plugin 0.0.1

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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -0
  3. package/lib/configs/modernization.d.ts +2 -0
  4. package/lib/configs/modernization.js +17 -0
  5. package/lib/configs/module-replacements.d.ts +2 -0
  6. package/lib/configs/module-replacements.js +8 -0
  7. package/lib/configs/performance-improvements.d.ts +2 -0
  8. package/lib/configs/performance-improvements.js +9 -0
  9. package/lib/configs/recommended.d.ts +2 -0
  10. package/lib/configs/recommended.js +18 -0
  11. package/lib/main.d.ts +3 -0
  12. package/lib/main.js +48 -0
  13. package/lib/rules/no-indexof-equality.d.ts +2 -0
  14. package/lib/rules/no-indexof-equality.js +90 -0
  15. package/lib/rules/prefer-array-at.d.ts +2 -0
  16. package/lib/rules/prefer-array-at.js +58 -0
  17. package/lib/rules/prefer-array-fill.d.ts +2 -0
  18. package/lib/rules/prefer-array-fill.js +120 -0
  19. package/lib/rules/prefer-array-from-map.d.ts +2 -0
  20. package/lib/rules/prefer-array-from-map.js +57 -0
  21. package/lib/rules/prefer-array-to-reversed.d.ts +2 -0
  22. package/lib/rules/prefer-array-to-reversed.js +42 -0
  23. package/lib/rules/prefer-array-to-sorted.d.ts +2 -0
  24. package/lib/rules/prefer-array-to-sorted.js +43 -0
  25. package/lib/rules/prefer-array-to-spliced.d.ts +2 -0
  26. package/lib/rules/prefer-array-to-spliced.js +43 -0
  27. package/lib/rules/prefer-exponentiation-operator.d.ts +2 -0
  28. package/lib/rules/prefer-exponentiation-operator.js +42 -0
  29. package/lib/rules/prefer-includes.d.ts +2 -0
  30. package/lib/rules/prefer-includes.js +131 -0
  31. package/lib/rules/prefer-nullish-coalescing.d.ts +2 -0
  32. package/lib/rules/prefer-nullish-coalescing.js +131 -0
  33. package/lib/rules/prefer-object-has-own.d.ts +2 -0
  34. package/lib/rules/prefer-object-has-own.js +71 -0
  35. package/lib/rules/prefer-optimized-indexof.d.ts +2 -0
  36. package/lib/rules/prefer-optimized-indexof.js +90 -0
  37. package/lib/rules/prefer-settimeout-args.d.ts +2 -0
  38. package/lib/rules/prefer-settimeout-args.js +175 -0
  39. package/lib/rules/prefer-spread-syntax.d.ts +2 -0
  40. package/lib/rules/prefer-spread-syntax.js +109 -0
  41. package/lib/rules/prefer-timer-args.d.ts +2 -0
  42. package/lib/rules/prefer-timer-args.js +176 -0
  43. package/lib/rules/prefer-url-canparse.d.ts +2 -0
  44. package/lib/rules/prefer-url-canparse.js +139 -0
  45. package/lib/test/setup.d.ts +1 -0
  46. package/lib/test/setup.js +10 -0
  47. package/lib/utils/ast.d.ts +15 -0
  48. package/lib/utils/ast.js +47 -0
  49. package/lib/utils/typescript.d.ts +14 -0
  50. package/lib/utils/typescript.js +6 -0
  51. package/package.json +56 -0
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Checks if a CallExpression is a copy operation that creates a shallow copy of an array.
3
+ * e.g. concat(), slice(), slice(0)
4
+ */
5
+ export function isCopyCall(node) {
6
+ if (node.callee.type !== 'MemberExpression' ||
7
+ node.callee.property.type !== 'Identifier') {
8
+ return false;
9
+ }
10
+ const methodName = node.callee.property.name;
11
+ if ((methodName === 'concat' || methodName === 'slice') &&
12
+ node.arguments.length === 0) {
13
+ return true;
14
+ }
15
+ if (methodName === 'slice' &&
16
+ node.arguments.length === 1 &&
17
+ node.arguments[0]?.type === 'Literal' &&
18
+ node.arguments[0].value === 0) {
19
+ return true;
20
+ }
21
+ return false;
22
+ }
23
+ /**
24
+ * Extracts the array node from array copy patterns.
25
+ */
26
+ export function getArrayFromCopyPattern(node) {
27
+ if (node.type === 'CallExpression' &&
28
+ isCopyCall(node) &&
29
+ node.callee.type === 'MemberExpression') {
30
+ return node.callee.object;
31
+ }
32
+ if (node.type === 'ArrayExpression' &&
33
+ node.elements.length === 1 &&
34
+ node.elements[0]?.type === 'SpreadElement') {
35
+ return node.elements[0].argument;
36
+ }
37
+ return null;
38
+ }
39
+ /**
40
+ * Formats arguments from a CallExpression as a comma-separated string.
41
+ */
42
+ export function formatArguments(args, sourceCode) {
43
+ if (args.length === 0) {
44
+ return '';
45
+ }
46
+ return args.map((arg) => sourceCode.getText(arg)).join(', ');
47
+ }
@@ -0,0 +1,14 @@
1
+ import type { Rule } from 'eslint';
2
+ import type { TSNode, TSToken, TSESTree } from '@typescript-eslint/typescript-estree';
3
+ import type ts from 'typescript';
4
+ export interface ParserServices {
5
+ emitDecoratorMetadata: boolean | undefined;
6
+ experimentalDecorators: boolean | undefined;
7
+ isolatedDeclarations: boolean | undefined;
8
+ esTreeNodeToTSNodeMap: WeakMap<TSESTree.Node, TSNode | TSToken>;
9
+ tsNodeToESTreeNodeMap: WeakMap<TSNode | TSToken, TSESTree.Node>;
10
+ getSymbolAtLocation: (node: TSESTree.Node) => ts.Symbol | undefined;
11
+ getTypeAtLocation: (node: TSESTree.Node) => ts.Type;
12
+ program: ts.Program;
13
+ }
14
+ export declare function getTypedParserServices(context: Readonly<Rule.RuleContext>): ParserServices;
@@ -0,0 +1,6 @@
1
+ export function getTypedParserServices(context) {
2
+ if (context.sourceCode.parserServices.program == null) {
3
+ throw new Error(`You have used a rule which requires type information. Please ensure you have typescript-eslint setup alongside this plugin and configured to enable type-aware linting. See https://typescript-eslint.io/getting-started/typed-linting for more information.`);
4
+ }
5
+ return context.sourceCode.parserServices;
6
+ }
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@e18e/eslint-plugin",
3
+ "version": "0.0.1",
4
+ "description": "The official e18e ESLint plugin for modernizing code and improving performance.",
5
+ "keywords": [
6
+ "eslint",
7
+ "e18e",
8
+ "performance",
9
+ "bloat",
10
+ "perf"
11
+ ],
12
+ "files": [
13
+ "lib",
14
+ "!lib/**/*.test.js",
15
+ "!lib/**/*.test.d.ts"
16
+ ],
17
+ "homepage": "https://github.com/e18e/eslint-plugin#readme",
18
+ "bugs": {
19
+ "url": "https://github.com/e18e/eslint-plugin/issues"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/e18e/eslint-plugin.git"
24
+ },
25
+ "license": "MIT",
26
+ "author": "James Garbutt (https://github.com/43081j)",
27
+ "type": "module",
28
+ "main": "lib/main.js",
29
+ "scripts": {
30
+ "build": "tsc",
31
+ "test": "vitest run",
32
+ "format": "prettier --write src",
33
+ "lint": "npm run lint:js && npm run lint:format",
34
+ "lint:js": "eslint src",
35
+ "lint:format": "prettier --check src"
36
+ },
37
+ "devDependencies": {
38
+ "@eslint/js": "^9.39.2",
39
+ "@types/node": "^25.0.3",
40
+ "@typescript-eslint/rule-tester": "^8.50.0",
41
+ "@typescript-eslint/typescript-estree": "^8.50.0",
42
+ "@vitest/coverage-v8": "^4.0.16",
43
+ "eslint": "^9.39.2",
44
+ "eslint-plugin-eslint-plugin": "^7.2.0",
45
+ "prettier": "^3.7.4",
46
+ "typescript": "^5.9.3",
47
+ "typescript-eslint": "^8.50.0",
48
+ "vitest": "^4.0.14"
49
+ },
50
+ "peerDependencies": {
51
+ "eslint": "^9.0.0"
52
+ },
53
+ "dependencies": {
54
+ "eslint-plugin-depend": "^1.4.0"
55
+ }
56
+ }