eslint-plugin-complete 1.0.2 → 1.0.4

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 CHANGED
@@ -1,114 +1,7 @@
1
1
  # `eslint-plugin-complete`
2
2
 
3
- `eslint-plugin-complete` is a collection of miscellaneous [ESLint](https://eslint.org/) rules that can help make your TypeScript code more safe or more strict.
3
+ [![npm version](https://img.shields.io/npm/v/eslint-plugin-complete.svg)](https://www.npmjs.com/package/eslint-plugin-complete)
4
4
 
5
- If you already have ESLint set up in your project, then you can try enabling the [`complete/recommend`](#configs) config to get all of the goodness from this plugin in your project at once. Alternatively, if you want more control, feel free to enable the specific rules that you need.
5
+ This is an [ESLint](https://eslint.org/) plugin containing rules that can help make your TypeScript code more safe or more strict.
6
6
 
7
- Alternatively, if you want to get off the ground and running with ESLint + TypeScript in a new project, then you should check out the [`complete-lint`](https://github.com/complete-ts/complete/tree/main/packages/complete-lint) meta-package.
8
-
9
- ## Install / Usage
10
-
11
- If you do not want to use the `complete-lint` meta-package, then you can install this plugin manually:
12
-
13
- - `npm install --save-dev eslint typescript eslint-plugin-complete` (`eslint` and `typescript` are peer-dependencies)
14
- - TODO
15
- - Add `"plugin:complete/recommended"` to the `extends` section of your `.eslintrc.cjs` file. (This will automatically add the plugin and add all of the recommended rules.)
16
- - Alternatively, if you want to only enable some specific rules, then add `"complete"` to the `plugins` section of your `.eslintrc.cjs` file, and then add the specific rules that you want in the `rules` section.
17
-
18
- ## Configs
19
-
20
- - `recommended` - Currently, every rule in this plugin is recommended.
21
-
22
- ## Rules
23
-
24
- Each rule has emojis denoting:
25
-
26
- - :white_check_mark: - if it belongs to the `recommended` configuration
27
- - :wrench: - if some problems reported by the rule are automatically fixable by the `--fix` [command line option](https://eslint.org/docs/latest/user-guide/command-line-interface#fixing-problems)
28
- - :thought_balloon: - if it requires type information
29
-
30
- <!-- Do not manually modify the RULES_TABLE section. Instead, run: npm run generate -->
31
- <!-- RULES_TABLE -->
32
-
33
- | Name | Description | :white_check_mark: | :wrench: | :thought_balloon: |
34
- | ----------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ------------------ | -------- | ----------------- |
35
- | [`complete/complete-sentences-jsdoc`](docs/rules/complete-sentences-jsdoc.md) | Requires complete sentences for JSDoc comments | :white_check_mark: | | |
36
- | [`complete/complete-sentences-line-comments`](docs/rules/complete-sentences-line-comments.md) | Requires complete sentences for multi-line leading line comments | :white_check_mark: | | |
37
- | [`complete/consistent-enum-values`](docs/rules/consistent-enum-values.md) | Requires consistent enum values | :white_check_mark: | | |
38
- | [`complete/consistent-named-tuples`](docs/rules/consistent-named-tuples.md) | Requires that if one or more tuple elements are named, all of them are named | :white_check_mark: | | |
39
- | [`complete/eqeqeq-fix`](docs/rules/eqeqeq-fix.md) | Requires the use of `===` and `!==` (and automatically fixes) | :white_check_mark: | :wrench: | |
40
- | [`complete/format-jsdoc-comments`](docs/rules/format-jsdoc-comments.md) | Disallows `/**` comments longer than N characters and multi-line comments that can be merged together | :white_check_mark: | :wrench: | |
41
- | [`complete/format-line-comments`](docs/rules/format-line-comments.md) | Disallows `//` comments longer than N characters and multi-line comments that can be merged together | :white_check_mark: | :wrench: | |
42
- | [`complete/jsdoc-code-block-language`](docs/rules/jsdoc-code-block-language.md) | Requires a language specification for every JSDoc code block | :white_check_mark: | | |
43
- | [`complete/newline-between-switch-case`](docs/rules/newline-between-switch-case.md) | Requires newlines between switch cases | :white_check_mark: | :wrench: | |
44
- | [`complete/no-confusing-set-methods`](docs/rules/no-confusing-set-methods.md) | Disallows confusing methods for sets | :white_check_mark: | | :thought_balloon: |
45
- | [`complete/no-empty-jsdoc`](docs/rules/no-empty-jsdoc.md) | Disallows empty JSDoc comments | :white_check_mark: | :wrench: | |
46
- | [`complete/no-empty-line-comments`](docs/rules/no-empty-line-comments.md) | Disallows empty line comments | :white_check_mark: | :wrench: | |
47
- | [`complete/no-explicit-array-loops`](docs/rules/no-explicit-array-loops.md) | Disallows explicit iteration for arrays | :white_check_mark: | :wrench: | :thought_balloon: |
48
- | [`complete/no-explicit-map-set-loops`](docs/rules/no-explicit-map-set-loops.md) | Disallows explicit iteration for maps and sets | :white_check_mark: | :wrench: | :thought_balloon: |
49
- | [`complete/no-for-in`](docs/rules/no-for-in.md) | Disallows "for x in y" statements | :white_check_mark: | | |
50
- | [`complete/no-let-any`](docs/rules/no-let-any.md) | Disallows declaring variables with let that do not have a type | :white_check_mark: | | :thought_balloon: |
51
- | [`complete/no-mutable-return`](docs/rules/no-mutable-return.md) | Disallows returning mutable arrays, maps, and sets from functions | :white_check_mark: | | :thought_balloon: |
52
- | [`complete/no-number-enums`](docs/rules/no-number-enums.md) | Disallows number enums | :white_check_mark: | | |
53
- | [`complete/no-object-any`](docs/rules/no-object-any.md) | Disallows declaring objects and arrays that do not have a type | :white_check_mark: | | :thought_balloon: |
54
- | [`complete/no-object-methods-with-map-set`](docs/rules/no-object-methods-with-map-set.md) | Disallows using object methods with maps and sets | :white_check_mark: | | :thought_balloon: |
55
- | [`complete/no-string-length-0`](docs/rules/no-string-length-0.md) | Disallows checking for empty strings via the length method in favor of direct comparison to an empty string | :white_check_mark: | | :thought_balloon: |
56
- | [`complete/no-template-curly-in-string-fix`](docs/rules/no-template-curly-in-string-fix.md) | Disallows template literal placeholder syntax in regular strings (and automatically fixes) | :white_check_mark: | :wrench: | |
57
- | [`complete/no-undefined-return-type`](docs/rules/no-undefined-return-type.md) | Disallows `undefined` return types on functions | :white_check_mark: | | :thought_balloon: |
58
- | [`complete/no-unnecessary-assignment`](docs/rules/no-unnecessary-assignment.md) | Disallows useless assignments | :white_check_mark: | | :thought_balloon: |
59
- | [`complete/no-unsafe-plusplus`](docs/rules/no-unsafe-plusplus.md) | Disallow unsafe and confusing uses of the "++" and "--" operators | :white_check_mark: | | :thought_balloon: |
60
- | [`complete/no-useless-return`](docs/rules/no-useless-return.md) | Disallow redundant return statements (with no auto-fixer) | :white_check_mark: | | |
61
- | [`complete/no-void-return-type`](docs/rules/no-void-return-type.md) | Disallows `void` return types on non-exported functions | :white_check_mark: | :wrench: | |
62
- | [`complete/prefer-const`](docs/rules/prefer-const.md) | Require `const` declarations for variables that are never reassigned after declared (with no auto-fixer) | :white_check_mark: | | |
63
- | [`complete/prefer-plusplus`](docs/rules/prefer-plusplus.md) | Require "++" or "--" operators instead of assignment operators where applicable | :white_check_mark: | :wrench: | |
64
- | [`complete/prefer-postfix-plusplus`](docs/rules/prefer-postfix-plusplus.md) | Require "i++" instead of "++i" | :white_check_mark: | | :thought_balloon: |
65
- | [`complete/prefer-readonly-parameter-types`](docs/rules/prefer-readonly-parameter-types.md) | Require function parameters to be typed as `readonly` to prevent accidental mutation of inputs | :white_check_mark: | | :thought_balloon: |
66
- | [`complete/require-break`](docs/rules/require-break.md) | Requires that each case of a switch statement has a `break` statement | :white_check_mark: | | |
67
- | [`complete/require-capital-const-assertions`](docs/rules/require-capital-const-assertions.md) | Requires a capital letter for named objects and arrays that have a const assertion | :white_check_mark: | :wrench: | |
68
- | [`complete/require-capital-read-only`](docs/rules/require-capital-read-only.md) | Requires maps/sets/arrays with a capital letter to be read-only | :white_check_mark: | | :thought_balloon: |
69
- | [`complete/require-unannotated-const-assertions`](docs/rules/require-unannotated-const-assertions.md) | Disallows explicit type annotations for variables that have a const assertion | :white_check_mark: | | |
70
- | [`complete/require-variadic-function-argument`](docs/rules/require-variadic-function-argument.md) | Requires that variadic functions must be supplied with at least one argument | :white_check_mark: | | :thought_balloon: |
71
- | [`complete/strict-array-methods`](docs/rules/strict-array-methods.md) | Requires boolean return types on array method functions | :white_check_mark: | | :thought_balloon: |
72
- | [`complete/strict-enums`](docs/rules/strict-enums.md) | Disallows the usage of unsafe enum patterns | :white_check_mark: | | :thought_balloon: |
73
- | [`complete/strict-undefined-functions`](docs/rules/strict-undefined-functions.md) | Disallows empty return statements in functions annotated as returning undefined | :white_check_mark: | | :thought_balloon: |
74
- | [`complete/strict-void-functions`](docs/rules/strict-void-functions.md) | Disallows non-empty return statements in functions annotated as returning void | :white_check_mark: | | |
75
-
76
- <!-- /RULES_TABLE -->
77
-
78
- ## Automatic Fixing
79
-
80
- You probably already use [Prettier](https://prettier.io/), which is helpful to automatically format files. You probably even have your IDE set up to run Prettier every time your save a file. This kind of thing saves you a tremendous amount of time - you can type out a bunch of code completely unformatted, and then press `Ctrl + s` at the end to automatically fix everything. (Alternatively, you could press `Ctrl + shift + f` to format the file without saving it, but it's simpler to just use one hotkey for everything.)
81
-
82
- In a similar way to Prettier, this ESLint plugin contains several rules that are designed to automatically apply whenever you save the file (like the [`format-jsdoc-comments`](docs/rules/format-jsdoc-comments.md) rule). These rules are "fixers", which are applied when ESLint is executed with the "--fix" flag. So, in the same way that you configure Prettier to run on save, you should also configure `eslint --fix` to run on save.
83
-
84
- For example, if you use [VSCode](https://code.visualstudio.com/), and you have the [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) and the [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) extensions installed, you can add the following to your repository's `.vscode/settings.json` file:
85
-
86
- ```jsonc
87
- {
88
- // Automatically run the formatter when certain files are saved.
89
- "[javascript][typescript][javascriptreact][typescriptreact]": {
90
- "editor.codeActionsOnSave": {
91
- "source.fixAll.eslint": "explicit",
92
- },
93
- "editor.defaultFormatter": "esbenp.prettier-vscode",
94
- "editor.formatOnSave": true,
95
- },
96
- }
97
- ```
98
-
99
- ## Comment Formatting
100
-
101
- For a discussion around comments and the motivations for some of the comment rules in the plugin, see [this page](docs/comments.md).
102
-
103
- ## Contributing
104
-
105
- Thanks for helping out with this open-source project!
106
-
107
- If you are adding a new rule, start by using the `create-rule` script to automate a few things:
108
-
109
- ```sh
110
- npm run create-rule foo "This is a description of the foo rule."
111
- git status # Show what the script did.
112
- ```
113
-
114
- Additionally, You can contact me [on Discord](https://discord.gg/KapmKQ2gUD) if you are doing a PR and have questions.
7
+ Please see the [docs](https://complete-ts.github.io/eslint-plugin-complete) for more information.
@@ -1 +1 @@
1
- {"version":3,"file":"recommended.d.ts","sourceRoot":"","sources":["../../src/configs/recommended.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,MAAM,EA2DnD,CAAC"}
1
+ {"version":3,"file":"recommended.d.ts","sourceRoot":"","sources":["../../src/configs/recommended.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,MAAM,EA+DnD,CAAC"}
@@ -5,10 +5,6 @@ export const recommended = [
5
5
  {
6
6
  plugins: {},
7
7
  rules: {
8
- eqeqeq: "off",
9
- "no-useless-return": "off",
10
- "no-template-curly-in-string": "off",
11
- "prefer-const": "off",
12
8
  "complete/complete-sentences-jsdoc": "error",
13
9
  "complete/complete-sentences-line-comments": "error",
14
10
  "complete/consistent-enum-values": "error",
@@ -51,6 +47,14 @@ export const recommended = [
51
47
  "complete/strict-void-functions": "error",
52
48
  },
53
49
  },
50
+ {
51
+ rules: {
52
+ eqeqeq: "off",
53
+ "no-useless-return": "off",
54
+ "no-template-curly-in-string": "off",
55
+ "prefer-const": "off",
56
+ },
57
+ },
54
58
  {
55
59
  files: ["**/*.js", "**/*.cjs", "**/*.mjs", "**/*.jsx"],
56
60
  rules: {
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { TSESLint } from "@typescript-eslint/utils";
2
2
  declare const plugin: {
3
3
  meta: {
4
- name: unknown;
5
- version: unknown;
4
+ name: string;
5
+ version: string;
6
6
  };
7
7
  configs: {
8
8
  recommended: TSESLint.FlatConfig.Config[];
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { configs } from "./configs.js";
4
4
  import { rules } from "./rules.js";
5
- const { name, version } = getPackageJSON();
5
+ const { name, version } = getPackageJSONNameAndVersion();
6
6
  const plugin = {
7
7
  meta: {
8
8
  name,
@@ -16,16 +16,28 @@ export default plugin;
16
16
  /**
17
17
  * We parse the package JSON manually since importing JSON files directly in Node is experimental.
18
18
  */
19
- function getPackageJSON() {
19
+ function getPackageJSONNameAndVersion() {
20
20
  const packageRoot = path.join(import.meta.dirname, "..");
21
21
  const packageJSONPath = path.join(packageRoot, "package.json");
22
+ let packageJSON;
22
23
  try {
23
24
  const packageJSONString = fs.readFileSync(packageJSONPath, "utf8");
24
- return JSON.parse(packageJSONString);
25
+ packageJSON = JSON.parse(packageJSONString);
25
26
  }
26
27
  catch (error) {
27
28
  throw new Error(`Failed to read the "${packageJSONPath}" file: ${error}`);
28
29
  }
30
+ // eslint-disable-next-line @typescript-eslint/no-shadow
31
+ const { name } = packageJSON;
32
+ if (typeof name !== "string") {
33
+ throw new TypeError('Failed to parse the "name" property of the "package.json" file.');
34
+ }
35
+ // eslint-disable-next-line @typescript-eslint/no-shadow
36
+ const { version } = packageJSON;
37
+ if (typeof version !== "string") {
38
+ throw new TypeError('Failed to parse the "version" property of the "package.json" file.');
39
+ }
40
+ return { name, version };
29
41
  }
30
42
  /** @see https://eslint.org/docs/latest/extend/plugins#configs-in-plugins */
31
43
  function addPluginToConfigs(configsToMutate, packageName) {
@@ -57,9 +57,15 @@ export const requireVariadicFunctionArgument = createRule({
57
57
  });
58
58
  function isHardCodedException(node) {
59
59
  const { callee } = node;
60
- return isConsoleOrWindowFunction(callee) || isTimeoutFunction(callee);
60
+ return isConsoleOrWindowOrLoggerFunction(callee) || isTimeoutFunction(callee);
61
61
  }
62
- function isConsoleOrWindowFunction(callee) {
62
+ /**
63
+ * This rule has a false positive with any logger function. (Both `console.log` and logger functions
64
+ * from logging libraries like Pino and Winston are affected.)
65
+ *
66
+ * e.g. `logger.info("hello world");`
67
+ */
68
+ function isConsoleOrWindowOrLoggerFunction(callee) {
63
69
  if (callee.type !== AST_NODE_TYPES.MemberExpression) {
64
70
  return false;
65
71
  }
@@ -67,7 +73,9 @@ function isConsoleOrWindowFunction(callee) {
67
73
  if (object.type !== AST_NODE_TYPES.Identifier) {
68
74
  return false;
69
75
  }
70
- return object.name === "console" || object.name === "window";
76
+ return (object.name === "console" ||
77
+ object.name === "window" ||
78
+ object.name === "logger");
71
79
  }
72
80
  function isTimeoutFunction(callee) {
73
81
  if (callee.type !== AST_NODE_TYPES.Identifier) {
package/dist/utils.js CHANGED
@@ -21,7 +21,7 @@ export function areStringsEqualExcludingTrailingSpaces(string1, string2) {
21
21
  }
22
22
  /** @see https://typescript-eslint.io/developers/custom-rules#extra-rule-docs-types */
23
23
  // eslint-disable-next-line new-cap
24
- export const createRule = ESLintUtils.RuleCreator((ruleName) => `https://github.com/complete-ts/complete/blob/main/packages/eslint-plugin-complete/docs/rules/${ruleName}.md`);
24
+ export const createRule = ESLintUtils.RuleCreator((ruleName) => `https://complete-ts.github.io/eslint-plugin-complete/rules/${ruleName}`);
25
25
  /**
26
26
  * From: https://stackoverflow.com/questions/13627308/add-st-nd-rd-and-th-ordinal-suffix-to-a-number
27
27
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-complete",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "An ESLint plugin that contains useful rules.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -18,13 +18,13 @@
18
18
  "prettier",
19
19
  "sentences"
20
20
  ],
21
- "homepage": "https://complete-js.github.io/",
21
+ "homepage": "https://complete-ts.github.io/",
22
22
  "bugs": {
23
- "url": "https://github.com/complete-js/complete/issues"
23
+ "url": "https://github.com/complete-ts/complete/issues"
24
24
  },
25
25
  "repository": {
26
26
  "type": "git",
27
- "url": "git+https://github.com/complete-js/complete.git"
27
+ "url": "git+https://github.com/complete-ts/complete.git"
28
28
  },
29
29
  "license": "MIT",
30
30
  "author": "Zamiell",
@@ -44,18 +44,18 @@
44
44
  "test": "jest"
45
45
  },
46
46
  "dependencies": {
47
- "@typescript-eslint/type-utils": "^8.6.0",
48
- "@typescript-eslint/utils": "^8.6.0",
49
- "typescript-eslint": "^8.6.0"
47
+ "@typescript-eslint/type-utils": "^8.7.0",
48
+ "@typescript-eslint/utils": "^8.7.0",
49
+ "typescript-eslint": "^8.7.0"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@babel/core": "^7.25.2",
53
53
  "@babel/preset-env": "^7.25.4",
54
54
  "@babel/preset-typescript": "^7.24.7",
55
55
  "@types/jest": "^29.5.13",
56
- "@types/node": "^22.5.5",
57
- "@typescript-eslint/rule-tester": "^8.6.0",
58
- "@typescript-eslint/types": "^8.6.0",
56
+ "@types/node": "^22.7.4",
57
+ "@typescript-eslint/rule-tester": "^8.7.0",
58
+ "@typescript-eslint/types": "^8.7.0",
59
59
  "complete-common": "^1.0.0",
60
60
  "complete-node": "^1.5.1",
61
61
  "jest": "^29.7.0",