eslint-config-isaacscript 5.0.0 → 5.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 (3) hide show
  1. package/package.json +4 -5
  2. package/src/index.js +1 -0
  3. package/src/mod.js +203 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-config-isaacscript",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "description": "A sharable ESLint config for TypeScript and IsaacScript projects.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -22,13 +22,12 @@
22
22
  "license": "MIT",
23
23
  "author": "Zamiell",
24
24
  "type": "module",
25
+ "main": "./src/index.js",
25
26
  "files": [
26
- "configs",
27
- "base.js",
28
27
  "LICENSE",
29
- "mod.js",
30
28
  "package.json",
31
- "README.md"
29
+ "README.md",
30
+ "src"
32
31
  ],
33
32
  "scripts": {
34
33
  "lint": "tsx ./scripts/lint.ts"
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export { isaacScriptModConfigBase } from "./mod.js";
package/src/mod.js ADDED
@@ -0,0 +1,203 @@
1
+ import ESLintPluginIsaacScript from "eslint-plugin-isaacscript";
2
+ import tseslint from "typescript-eslint";
3
+
4
+ // Hot-patch "eslint-plugin-isaacscript" to convert errors to warnings.
5
+ for (const config of ESLintPluginIsaacScript.configs.recommended) {
6
+ if (config.rules !== undefined) {
7
+ for (const [key, value] of Object.entries(config.rules)) {
8
+ if (value === "error") {
9
+ config.rules[key] = "warn";
10
+ }
11
+ }
12
+ }
13
+ }
14
+
15
+ /**
16
+ * This ESLint config is meant to be used as a base for IsaacScript mods (or TypeScriptToLua
17
+ * projects).
18
+ */
19
+ export const isaacScriptModConfigBase = tseslint.config(
20
+ // `eslint-plugin-isaacscript` provides rules specifically for IsaacScript mods.
21
+ ...ESLintPluginIsaacScript.configs.recommended,
22
+
23
+ {
24
+ rules: {
25
+ /**
26
+ * Defined at: base-typescript-eslint.js
27
+ *
28
+ * It is conventional in IsaacScript mods to put the "v" object outside of the class, which
29
+ * makes it likely that some methods will not use any internal class variables.
30
+ */
31
+ "@typescript-eslint/class-methods-use-this": "off",
32
+
33
+ /**
34
+ * Defined at: base-typescript-eslint.js
35
+ *
36
+ * We expand the original definition to ensure that all enums match the Isaac convention of
37
+ * using UPPER_CASE.
38
+ */
39
+ "@typescript-eslint/naming-convention": [
40
+ "warn",
41
+ // Allow camelCase variables (23.2), PascalCase variables (23.8), and UPPER_CASE variables
42
+ // (23.10).
43
+ {
44
+ selector: "variable",
45
+ format: ["camelCase", "PascalCase", "UPPER_CASE"],
46
+ leadingUnderscore: "allow",
47
+ },
48
+ // Allow camelCase functions (23.2), and PascalCase functions (23.8).
49
+ {
50
+ selector: "function",
51
+ format: ["camelCase", "PascalCase"],
52
+ leadingUnderscore: "allow",
53
+ },
54
+ // Airbnb recommends PascalCase for classes (23.3), and although Airbnb does not make
55
+ // TypeScript recommendations, we are assuming this rule would similarly apply to anything
56
+ // "type like", including interfaces, type aliases, and enums.
57
+ {
58
+ selector: "typeLike",
59
+ format: ["PascalCase"],
60
+ leadingUnderscore: "allow",
61
+ },
62
+ // The vanilla Isaac enums all use UPPER_CASE:
63
+ // https://wofsauge.github.io/IsaacDocs/rep/enums/CollectibleType.html
64
+ {
65
+ selector: "enumMember",
66
+ format: ["UPPER_CASE"],
67
+ },
68
+ ],
69
+
70
+ /**
71
+ * Defined at: base-typescript-eslint.js
72
+ *
73
+ * The `Vector` object has a `tostring` meta-method, so it can be properly printed without
74
+ * explicitly specifying the X and Y values.
75
+ */
76
+ "@typescript-eslint/no-base-to-string": [
77
+ "warn",
78
+ {
79
+ ignoredTypeNames: ["Vector"],
80
+ },
81
+ ],
82
+
83
+ /**
84
+ * Defined at: base-typescript-eslint.js
85
+ *
86
+ * TSTL has special behavior with respect to `this: void`, so we need to configure this rule
87
+ * to allow the `this` parameter.
88
+ */
89
+ "@typescript-eslint/no-invalid-void-type": [
90
+ "warn",
91
+ {
92
+ allowAsThisParameter: true,
93
+ },
94
+ ],
95
+
96
+ /**
97
+ * Defined at: base-typescript-eslint.js
98
+ *
99
+ * This rule throws false positives with Isaac API functions. It can be worked around by
100
+ * supplying lists of globals to ESLint, but this is ugly. See:
101
+ * https://github.com/typescript-eslint/typescript-eslint/issues/2780
102
+ */
103
+ "@typescript-eslint/no-loop-func": "off",
104
+
105
+ /**
106
+ * Defined at: base-typescript-eslint.js
107
+ *
108
+ * Enums that are used with the API must be numbers since that is what the API expects. We
109
+ * also prefer that unofficial enums are also number enums for consistency.
110
+ */
111
+ "@typescript-eslint/prefer-enum-initializers": "off",
112
+
113
+ /**
114
+ * Defined at: base-typescript-eslint.js
115
+ *
116
+ * It is common to initialize enums with the `Isaac.GetEntityVariantByName` method.
117
+ */
118
+ "@typescript-eslint/prefer-literal-enum-member": "off",
119
+
120
+ /**
121
+ * Defined at: base-typescript-eslint.js
122
+ *
123
+ * The `Number.sort` method transpiles to use `table.sort`, which does not have the
124
+ * coercion-based bugs of the JavaScript implementation. Thus, this lint rule is unnecessary.
125
+ */
126
+ "@typescript-eslint/require-array-sort-compare": "off",
127
+
128
+ /**
129
+ * Defined in "complete/recommended".
130
+ *
131
+ * Enums that are used with the API use upper case letters. We also prefer that unofficial
132
+ * enums are also use upper case letters for consistency.
133
+ */
134
+ "complete/consistent-enum-values": "off",
135
+
136
+ /**
137
+ * Defined in "complete/recommended".
138
+ *
139
+ * Enums that are used with the API must be numbers since that is what the API expects. We
140
+ * also prefer that unofficial enums are also number enums for consistency.
141
+ */
142
+ "complete/no-number-enums": "off",
143
+
144
+ /**
145
+ * Defined at: base-n.js
146
+ *
147
+ * IsaacScript mods to not use ESM, so we must turn this rule off.
148
+ */
149
+ "n/file-extension-in-import": "off",
150
+
151
+ /**
152
+ * Defined at: base-unicorn.js
153
+ *
154
+ * `null` values are conventionally used with the `isaacscript-common` save data manager (even
155
+ * though they are transpiled to `nil`).
156
+ */
157
+ "unicorn/no-null": "off",
158
+
159
+ /**
160
+ * Defined at: base-unicorn.js
161
+ *
162
+ * IsaacScript mods use Lua bitwise operators, which are safe.
163
+ */
164
+ "unicorn/prefer-math-trunc": "off",
165
+
166
+ /**
167
+ * Defined at: base-eslint.js
168
+ *
169
+ * Isaac API methods use capital letters, so we must make the options for the rule less
170
+ * strict.
171
+ */
172
+ "new-cap": [
173
+ "warn",
174
+ {
175
+ newIsCap: true,
176
+ capIsNew: false,
177
+ properties: true,
178
+ },
179
+ ],
180
+
181
+ /**
182
+ * Defined at: base-eslint.js
183
+ *
184
+ * Isaac enums use bitwise operators (e.g. "EntityFlag").
185
+ */
186
+ "no-bitwise": "off",
187
+
188
+ /**
189
+ * Defined at: base-eslint.js
190
+ *
191
+ * The Isaac API callback functions expect you to modify the provided object.
192
+ */
193
+ "no-param-reassign": "off",
194
+
195
+ /**
196
+ * Defined at: base-eslint.js
197
+ *
198
+ * "print" is used with Lua mods.
199
+ */
200
+ "no-restricted-globals": "off",
201
+ },
202
+ },
203
+ );