@rotki/eslint-plugin 0.0.3 → 0.1.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 CHANGED
@@ -13,4 +13,4 @@ See [here](https://rotki.github.io/eslint-plugin)
13
13
 
14
14
  ## License
15
15
 
16
- [AGPL-3.0](./LICENSE) License © 2023- [Rotki Solutions GmbH](https://github.com/rotki)
16
+ [AGPL-3.0](./LICENSE) License © 2023- [Rotki Solutions GmbH](https://github.com/rotki)
package/dist/index.cjs ADDED
@@ -0,0 +1,409 @@
1
+ 'use strict';
2
+
3
+ const node_path = require('node:path');
4
+ const compat = require('eslint-compat-utils');
5
+ const createDebug = require('debug');
6
+ const scule = require('scule');
7
+
8
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
9
+
10
+ function _interopNamespaceCompat(e) {
11
+ if (e && typeof e === 'object' && 'default' in e) return e;
12
+ const n = Object.create(null);
13
+ if (e) {
14
+ for (const k in e) {
15
+ n[k] = e[k];
16
+ }
17
+ }
18
+ n.default = e;
19
+ return n;
20
+ }
21
+
22
+ const compat__namespace = /*#__PURE__*/_interopNamespaceCompat(compat);
23
+ const createDebug__default = /*#__PURE__*/_interopDefaultCompat(createDebug);
24
+
25
+ const name = "@rotki/eslint-plugin";
26
+ const version = "0.1.0";
27
+ const packageManager = "pnpm@8.14.1";
28
+ const type = "module";
29
+ const license = "AGPL-3.0";
30
+ const bugs = {
31
+ url: "https://github.com/rotki/eslint-plugin/issues"
32
+ };
33
+ const repository = {
34
+ type: "git",
35
+ url: "https://github.com/rotki/eslint-plugin.git"
36
+ };
37
+ const author = "Rotki Solutions GmbH <info@rotki.com>";
38
+ const files = [
39
+ "dist"
40
+ ];
41
+ const main = "./dist/index.mjs";
42
+ const module$1 = "./dist/index.mjs";
43
+ const types = "./dist/index.d.ts";
44
+ const exports$1 = {
45
+ ".": {
46
+ types: "./dist/index.d.ts",
47
+ require: "./dist/index.cjs",
48
+ "import": "./dist/index.mjs"
49
+ }
50
+ };
51
+ const sideEffects = false;
52
+ const scripts = {
53
+ clean: "rimraf .nyc_output coverage dist docs/.vitepress/dist",
54
+ coverage: "nyc report --reporter lcov && opener coverage/lcov-report/index.html",
55
+ generate: "node --experimental-specifier-resolution=node --loader ts-node/esm scripts/update-rule-docs.ts",
56
+ lint: "eslint .",
57
+ "lint:fix": "eslint . --fix",
58
+ build: "unbuild",
59
+ dev: "unbuild --stub",
60
+ prepublishOnly: "pnpm run build",
61
+ test: "vitest",
62
+ "new": "node --experimental-specifier-resolution=node --loader ts-node/esm ./scripts/new-rule.ts",
63
+ docs: "vitepress dev docs",
64
+ "docs:build": "pnpm run generate && vitepress build docs",
65
+ prepare: "husky install",
66
+ typecheck: "tsc --noEmit",
67
+ release: "bumpp -r --no-push"
68
+ };
69
+ const peerDependencies = {
70
+ eslint: "^8.0.0 || ^9.0.0"
71
+ };
72
+ const dependencies = {
73
+ "@typescript-eslint/utils": "6.19.0",
74
+ debug: "4.3.4",
75
+ "eslint-compat-utils": "0.4.1",
76
+ "jsonc-eslint-parser": "2.4.0",
77
+ scule: "1.2.0",
78
+ "vue-eslint-parser": "9.4.1",
79
+ "yaml-eslint-parser": "1.2.2"
80
+ };
81
+ const devDependencies = {
82
+ "@commitlint/cli": "18.5.0",
83
+ "@commitlint/config-conventional": "18.5.0",
84
+ "@rotki/eslint-config": "2.3.0",
85
+ "@types/debug": "4.1.12",
86
+ "@types/eslint": "8.56.2",
87
+ "@types/node": "20",
88
+ "@typescript-eslint/eslint-plugin": "6.19.0",
89
+ "@typescript-eslint/parser": "6.19.0",
90
+ "@typescript-eslint/rule-tester": "6.19.0",
91
+ bumpp: "9.3.0",
92
+ eslint: "8.56.0",
93
+ husky: "8.0.3",
94
+ "lint-staged": "15.2.0",
95
+ rimraf: "5.0.5",
96
+ "ts-node": "10.9.2",
97
+ typescript: "5.3.3",
98
+ unbuild: "2.0.0",
99
+ vitepress: "1.0.0-rc.40",
100
+ vitest: "1.2.1"
101
+ };
102
+ const engines = {
103
+ node: ">=18.0.0",
104
+ pnpm: ">=8 <9"
105
+ };
106
+ const pkg = {
107
+ name: name,
108
+ version: version,
109
+ packageManager: packageManager,
110
+ type: type,
111
+ license: license,
112
+ bugs: bugs,
113
+ repository: repository,
114
+ author: author,
115
+ files: files,
116
+ main: main,
117
+ module: module$1,
118
+ types: types,
119
+ exports: exports$1,
120
+ sideEffects: sideEffects,
121
+ scripts: scripts,
122
+ peerDependencies: peerDependencies,
123
+ dependencies: dependencies,
124
+ devDependencies: devDependencies,
125
+ engines: engines,
126
+ "lint-staged": {
127
+ "*.{js,cjs,ts,vue,yml,json,md}": "eslint"
128
+ }
129
+ };
130
+
131
+ function getFilename(context) {
132
+ return compat__namespace.getFilename(context);
133
+ }
134
+ function getSourceCode(context) {
135
+ return compat__namespace.getSourceCode(context);
136
+ }
137
+
138
+ const blobUrl = "https://rotki.github.io/eslint-plugin/rules/";
139
+ function RuleCreator(urlCreator) {
140
+ return function createNamedRule({
141
+ meta,
142
+ name,
143
+ ...rule
144
+ }) {
145
+ return createRule({
146
+ meta: {
147
+ ...meta,
148
+ docs: {
149
+ ...meta.docs,
150
+ url: urlCreator(name)
151
+ }
152
+ },
153
+ ...rule
154
+ });
155
+ };
156
+ }
157
+ function createRule({
158
+ create,
159
+ defaultOptions,
160
+ meta
161
+ }) {
162
+ return {
163
+ create: (context) => {
164
+ const optionsWithDefault = context.options.map((options, index) => ({
165
+ ...defaultOptions[index] || {},
166
+ ...options || {}
167
+ }));
168
+ return create(context, optionsWithDefault);
169
+ },
170
+ defaultOptions,
171
+ meta
172
+ };
173
+ }
174
+ const createEslintRule = RuleCreator(
175
+ (ruleName) => `${blobUrl}${ruleName}`
176
+ );
177
+
178
+ function defineTemplateBodyVisitor(context, templateBodyVisitor, scriptVisitor, options) {
179
+ const sourceCode = getSourceCode(context);
180
+ const parserServices = sourceCode.parserServices;
181
+ if (!("defineTemplateBodyVisitor" in parserServices) || parserServices.defineTemplateBodyVisitor == null) {
182
+ const filename = getFilename(context);
183
+ if (node_path.extname(filename) === ".vue") {
184
+ context.report({
185
+ loc: { column: 0, line: 1 },
186
+ message: "Use the latest vue-eslint-parser. See also https://github.com/vuejs/eslint-plugin-vue#what-is-the-use-the-latest-vue-eslint-parser-error"
187
+ });
188
+ }
189
+ return {};
190
+ }
191
+ return parserServices.defineTemplateBodyVisitor(
192
+ templateBodyVisitor,
193
+ scriptVisitor,
194
+ options
195
+ );
196
+ }
197
+
198
+ const RULE_NAME$1 = "no-deprecated-classes";
199
+ const replacements$1 = [
200
+ ["d-block", "block"],
201
+ ["d-flex", "flex"],
202
+ ["flex-column", "flex-col"],
203
+ ["flex-grow-1", "grow"],
204
+ ["flex-grow-0", "grow-0"],
205
+ ["flex-shrink-1", "shrink"],
206
+ ["flex-shrink-0", "shrink-0"],
207
+ [
208
+ /^align-(start|end|center|baseline|stretch)$/,
209
+ ([align]) => `items-${align}`
210
+ ],
211
+ [/^justify-space-(between|around)$/, ([justify]) => `justify-${justify}`],
212
+ [
213
+ /^align-self-(start|end|center|baseline|auto|strech)$/,
214
+ ([align]) => `self-${align}`
215
+ ],
216
+ [
217
+ /^font-weight-(thin|extralight|light|normal|medium|semibold|bold|extrabold|black)$/,
218
+ ([weight]) => `font-${weight}`
219
+ ],
220
+ [/^text-(capitalize|uppercase|lowercase)$/, ([casing]) => casing]
221
+ ];
222
+ function isString(replacement) {
223
+ return typeof replacement[0] === "string";
224
+ }
225
+ function isRegex(replacement) {
226
+ return replacement[0] instanceof RegExp;
227
+ }
228
+ const noDeprecatedClasses = createEslintRule({
229
+ create(context) {
230
+ return defineTemplateBodyVisitor(context, {
231
+ 'VAttribute[key.name="class"]': function(node) {
232
+ if (!node.value || !node.value.value)
233
+ return;
234
+ const classes = node.value.value.split(/\s+/).filter((s) => !!s);
235
+ const source = getSourceCode(context);
236
+ const replaced = [];
237
+ classes.forEach((className) => {
238
+ for (const replacement of replacements$1) {
239
+ if (isString(replacement) && replacement[0] === className)
240
+ replaced.push([className, replacement[1]]);
241
+ if (isRegex(replacement)) {
242
+ const matches = (replacement[0].exec(className) || []).slice(1);
243
+ const replace = replacement[1];
244
+ if (matches.length > 0 && typeof replace === "function")
245
+ return replaced.push([className, replace(matches)]);
246
+ }
247
+ }
248
+ });
249
+ replaced.forEach((replacement) => {
250
+ if (!node.value)
251
+ return;
252
+ const idx = node.value.value.indexOf(replacement[0]) + 1;
253
+ const range = [
254
+ node.value.range[0] + idx,
255
+ node.value.range[0] + idx + replacement[0].length
256
+ ];
257
+ const loc = {
258
+ end: source.getLocFromIndex(range[1]),
259
+ start: source.getLocFromIndex(range[0])
260
+ };
261
+ context.report({
262
+ data: {
263
+ a: replacement[0],
264
+ b: replacement[1]
265
+ },
266
+ fix(fixer) {
267
+ return fixer.replaceTextRange(range, replacement[1]);
268
+ },
269
+ loc,
270
+ messageId: "replacedWith"
271
+ });
272
+ });
273
+ }
274
+ });
275
+ },
276
+ defaultOptions: [],
277
+ meta: {
278
+ docs: {
279
+ description: "disallow the usage of vuetify css classes since they are replaced with tailwindcss",
280
+ recommended: "recommended"
281
+ },
282
+ fixable: "code",
283
+ messages: {
284
+ replacedWith: `'{{ a }}' has been replaced with '{{ b }}'`
285
+ },
286
+ schema: [],
287
+ type: "problem"
288
+ },
289
+ name: RULE_NAME$1
290
+ });
291
+
292
+ const debug = createDebug__default("@rotki/eslint-plugin:no-deprecated-components");
293
+ const RULE_NAME = "no-deprecated-components";
294
+ const replacements = {
295
+ DataTable: true,
296
+ Fragment: false
297
+ };
298
+ const skipInLegacy = [
299
+ "Fragment"
300
+ ];
301
+ function hasReplacement(tag) {
302
+ return Object.prototype.hasOwnProperty.call(replacements, tag);
303
+ }
304
+ const noDeprecatedComponents = createEslintRule({
305
+ create(context, optionsWithDefault) {
306
+ const options = optionsWithDefault[0] || {};
307
+ const legacy = options.legacy;
308
+ return defineTemplateBodyVisitor(context, {
309
+ VElement(element) {
310
+ const tag = scule.pascalCase(element.rawName);
311
+ const sourceCode = getSourceCode(context);
312
+ if (!("getTemplateBodyTokenStore" in sourceCode.parserServices))
313
+ throw new Error("cannot find getTemplateBodyTokenStore in parserServices");
314
+ if (!hasReplacement(tag))
315
+ return;
316
+ const replacement = replacements[tag];
317
+ if (replacement || legacy && skipInLegacy.includes(tag)) {
318
+ debug(`${tag} has been deprecated`);
319
+ context.report({
320
+ data: {
321
+ name: scule.snakeCase(tag)
322
+ },
323
+ messageId: "deprecated",
324
+ node: element
325
+ });
326
+ } else {
327
+ debug(`${tag} has will be removed`);
328
+ context.report({
329
+ data: {
330
+ name: scule.snakeCase(tag)
331
+ },
332
+ fix(fixer) {
333
+ return [
334
+ fixer.remove(element.startTag),
335
+ ...element.endTag ? [fixer.remove(element.endTag)] : []
336
+ ];
337
+ },
338
+ messageId: "removed",
339
+ node: element
340
+ });
341
+ }
342
+ }
343
+ });
344
+ },
345
+ defaultOptions: [{ legacy: false }],
346
+ meta: {
347
+ docs: {
348
+ description: "Removes deprecated classes that do not exist anymore",
349
+ recommended: "recommended"
350
+ },
351
+ fixable: "code",
352
+ messages: {
353
+ deprecated: `'{{ name }}' has been deprecated`,
354
+ removed: `'{{ name }}' has been removed`,
355
+ replacedWith: `'{{ a }}' has been replaced with '{{ b }}'`
356
+ },
357
+ schema: [
358
+ {
359
+ additionalProperties: false,
360
+ properties: {
361
+ legacy: {
362
+ type: "boolean"
363
+ }
364
+ },
365
+ type: "object"
366
+ }
367
+ ],
368
+ type: "problem"
369
+ },
370
+ name: RULE_NAME
371
+ });
372
+
373
+ const plugin = {
374
+ meta: {
375
+ name: "@rotki/eslint-plugin",
376
+ version: pkg.version
377
+ },
378
+ rules: {
379
+ "no-deprecated-classes": noDeprecatedClasses,
380
+ "no-deprecated-components": noDeprecatedComponents
381
+ }
382
+ };
383
+ const plugin$1 = plugin;
384
+
385
+ function createRecommended(plugin, name, flat) {
386
+ const rules = Object.fromEntries(Object.entries(plugin.rules).filter(([_key, rule]) => rule.meta.recommended === "recommended" && !rule.meta.deprecated).map(([key]) => [`${name}/${key}`, 2]));
387
+ if (flat) {
388
+ return {
389
+ plugins: {
390
+ [name]: plugin
391
+ },
392
+ rules
393
+ };
394
+ } else {
395
+ return {
396
+ plugins: [name],
397
+ rules
398
+ };
399
+ }
400
+ }
401
+
402
+ const configs = {
403
+ "recommended": createRecommended(plugin$1, "@rotki", false),
404
+ "recommended-flat": createRecommended(plugin$1, "@rotki", true)
405
+ };
406
+
407
+ const index = Object.assign(plugin$1, { configs });
408
+
409
+ module.exports = index;
@@ -0,0 +1,88 @@
1
+ import { Rule, Linter } from 'eslint';
2
+
3
+ interface PluginRuleModule<TOptions extends readonly unknown[] = []> extends Rule.RuleModule {
4
+ defaultOptions: TOptions;
5
+ }
6
+
7
+ type Options = [{
8
+ legacy: boolean;
9
+ }];
10
+
11
+ declare const plugin: {
12
+ meta: {
13
+ name: string;
14
+ version: string;
15
+ };
16
+ rules: {
17
+ 'no-deprecated-classes': PluginRuleModule<[]>;
18
+ 'no-deprecated-components': PluginRuleModule<Options>;
19
+ };
20
+ };
21
+
22
+ declare const _default: {
23
+ meta: {
24
+ name: string;
25
+ version: string;
26
+ };
27
+ rules: {
28
+ 'no-deprecated-classes': PluginRuleModule<[]>;
29
+ 'no-deprecated-components': PluginRuleModule<Options>;
30
+ };
31
+ } & {
32
+ configs: {
33
+ recommended: {
34
+ plugins: {
35
+ [x: string]: {
36
+ meta: {
37
+ name: string;
38
+ version: string;
39
+ };
40
+ rules: {
41
+ 'no-deprecated-classes': PluginRuleModule<[]>;
42
+ 'no-deprecated-components': PluginRuleModule<Options>;
43
+ };
44
+ };
45
+ };
46
+ rules: {
47
+ [k: string]: number;
48
+ };
49
+ } | {
50
+ plugins: string[];
51
+ rules: {
52
+ [k: string]: number;
53
+ };
54
+ };
55
+ 'recommended-flat': {
56
+ plugins: {
57
+ [x: string]: {
58
+ meta: {
59
+ name: string;
60
+ version: string;
61
+ };
62
+ rules: {
63
+ 'no-deprecated-classes': PluginRuleModule<[]>;
64
+ 'no-deprecated-components': PluginRuleModule<Options>;
65
+ };
66
+ };
67
+ };
68
+ rules: {
69
+ [k: string]: number;
70
+ };
71
+ } | {
72
+ plugins: string[];
73
+ rules: {
74
+ [k: string]: number;
75
+ };
76
+ };
77
+ };
78
+ };
79
+
80
+ type RuleDefinitions = typeof plugin['rules'];
81
+ type RuleOptions = {
82
+ [K in keyof RuleDefinitions]: RuleDefinitions[K]['defaultOptions'];
83
+ };
84
+ type Rules = {
85
+ [K in keyof RuleOptions]: Linter.RuleEntry<RuleOptions[K]>;
86
+ };
87
+
88
+ export { type RuleOptions, type Rules, _default as default };
@@ -0,0 +1,88 @@
1
+ import { Rule, Linter } from 'eslint';
2
+
3
+ interface PluginRuleModule<TOptions extends readonly unknown[] = []> extends Rule.RuleModule {
4
+ defaultOptions: TOptions;
5
+ }
6
+
7
+ type Options = [{
8
+ legacy: boolean;
9
+ }];
10
+
11
+ declare const plugin: {
12
+ meta: {
13
+ name: string;
14
+ version: string;
15
+ };
16
+ rules: {
17
+ 'no-deprecated-classes': PluginRuleModule<[]>;
18
+ 'no-deprecated-components': PluginRuleModule<Options>;
19
+ };
20
+ };
21
+
22
+ declare const _default: {
23
+ meta: {
24
+ name: string;
25
+ version: string;
26
+ };
27
+ rules: {
28
+ 'no-deprecated-classes': PluginRuleModule<[]>;
29
+ 'no-deprecated-components': PluginRuleModule<Options>;
30
+ };
31
+ } & {
32
+ configs: {
33
+ recommended: {
34
+ plugins: {
35
+ [x: string]: {
36
+ meta: {
37
+ name: string;
38
+ version: string;
39
+ };
40
+ rules: {
41
+ 'no-deprecated-classes': PluginRuleModule<[]>;
42
+ 'no-deprecated-components': PluginRuleModule<Options>;
43
+ };
44
+ };
45
+ };
46
+ rules: {
47
+ [k: string]: number;
48
+ };
49
+ } | {
50
+ plugins: string[];
51
+ rules: {
52
+ [k: string]: number;
53
+ };
54
+ };
55
+ 'recommended-flat': {
56
+ plugins: {
57
+ [x: string]: {
58
+ meta: {
59
+ name: string;
60
+ version: string;
61
+ };
62
+ rules: {
63
+ 'no-deprecated-classes': PluginRuleModule<[]>;
64
+ 'no-deprecated-components': PluginRuleModule<Options>;
65
+ };
66
+ };
67
+ };
68
+ rules: {
69
+ [k: string]: number;
70
+ };
71
+ } | {
72
+ plugins: string[];
73
+ rules: {
74
+ [k: string]: number;
75
+ };
76
+ };
77
+ };
78
+ };
79
+
80
+ type RuleDefinitions = typeof plugin['rules'];
81
+ type RuleOptions = {
82
+ [K in keyof RuleDefinitions]: RuleDefinitions[K]['defaultOptions'];
83
+ };
84
+ type Rules = {
85
+ [K in keyof RuleOptions]: Linter.RuleEntry<RuleOptions[K]>;
86
+ };
87
+
88
+ export { type RuleOptions, type Rules, _default as default };
package/dist/index.d.ts CHANGED
@@ -1,29 +1,88 @@
1
+ import { Rule, Linter } from 'eslint';
2
+
3
+ interface PluginRuleModule<TOptions extends readonly unknown[] = []> extends Rule.RuleModule {
4
+ defaultOptions: TOptions;
5
+ }
6
+
7
+ type Options = [{
8
+ legacy: boolean;
9
+ }];
10
+
11
+ declare const plugin: {
12
+ meta: {
13
+ name: string;
14
+ version: string;
15
+ };
16
+ rules: {
17
+ 'no-deprecated-classes': PluginRuleModule<[]>;
18
+ 'no-deprecated-components': PluginRuleModule<Options>;
19
+ };
20
+ };
21
+
1
22
  declare const _default: {
23
+ meta: {
24
+ name: string;
25
+ version: string;
26
+ };
27
+ rules: {
28
+ 'no-deprecated-classes': PluginRuleModule<[]>;
29
+ 'no-deprecated-components': PluginRuleModule<Options>;
30
+ };
31
+ } & {
2
32
  configs: {
3
- base: {
4
- parser: string;
33
+ recommended: {
34
+ plugins: {
35
+ [x: string]: {
36
+ meta: {
37
+ name: string;
38
+ version: string;
39
+ };
40
+ rules: {
41
+ 'no-deprecated-classes': PluginRuleModule<[]>;
42
+ 'no-deprecated-components': PluginRuleModule<Options>;
43
+ };
44
+ };
45
+ };
46
+ rules: {
47
+ [k: string]: number;
48
+ };
49
+ } | {
5
50
  plugins: string[];
51
+ rules: {
52
+ [k: string]: number;
53
+ };
6
54
  };
7
- recommended: {
8
- extends: string[];
9
- parserOptions: {
10
- ecmaVersion: number;
11
- sourceType: string;
12
- ecmaFeatures: {
13
- jsx: boolean;
55
+ 'recommended-flat': {
56
+ plugins: {
57
+ [x: string]: {
58
+ meta: {
59
+ name: string;
60
+ version: string;
61
+ };
62
+ rules: {
63
+ 'no-deprecated-classes': PluginRuleModule<[]>;
64
+ 'no-deprecated-components': PluginRuleModule<Options>;
65
+ };
14
66
  };
15
67
  };
16
- env: {
17
- browser: boolean;
18
- es6: boolean;
68
+ rules: {
69
+ [k: string]: number;
19
70
  };
71
+ } | {
72
+ plugins: string[];
20
73
  rules: {
21
- '@rotki/no-deprecated-classes': "warn";
74
+ [k: string]: number;
22
75
  };
23
76
  };
24
77
  };
25
- rules: {
26
- 'no-deprecated-classes': import("./types").RuleModule;
27
- };
28
78
  };
29
- export = _default;
79
+
80
+ type RuleDefinitions = typeof plugin['rules'];
81
+ type RuleOptions = {
82
+ [K in keyof RuleDefinitions]: RuleDefinitions[K]['defaultOptions'];
83
+ };
84
+ type Rules = {
85
+ [K in keyof RuleOptions]: Linter.RuleEntry<RuleOptions[K]>;
86
+ };
87
+
88
+ export { type RuleOptions, type Rules, _default as default };