@dartess/eslint-plugin 0.1.0 → 0.2.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/CHANGELOG.md +6 -0
- package/README.md +1 -0
- package/dist/configs/recommended.js +2 -0
- package/dist/configs/vendor-rules/imports.js +4 -9
- package/dist/index.js +2 -0
- package/dist/rules/jsx-text-as-child.d.ts +1 -1
- package/dist/rules/prevent-mixing-external-and-internal-classes.d.ts +1 -1
- package/dist/rules/strict-observable-components-declaration.d.ts +1 -1
- package/dist/rules/ts-named-tuple-elements.d.ts +13 -0
- package/dist/rules/ts-named-tuple-elements.js +47 -0
- package/docs/rules/ts-named-tuple-elements.md +36 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
[//]: # (https://keepachangelog.com/en/1.1.0/)
|
|
4
4
|
|
|
5
|
+
## [0.2.0] - 2026-01-05
|
|
6
|
+
|
|
7
|
+
- improve `import-x/no-extraneous-dependencies` options
|
|
8
|
+
- add rule `@dartess/ts-named-tuple-elements`
|
|
9
|
+
- add `@dartess/ts-named-tuple-elements` to `recommended` config
|
|
10
|
+
|
|
5
11
|
## [0.1.0] - 2026-01-02
|
|
6
12
|
|
|
7
13
|
- add `eslint-plugin-de-morgan` to `recommended` config
|
package/README.md
CHANGED
|
@@ -148,6 +148,7 @@ Each rule has emojis denoting:
|
|
|
148
148
|
| [stories-export-meta](docs/rules/stories-export-meta.md) | Storybook's Meta should be typed | ✅ | | |
|
|
149
149
|
| [stories-export-typed](docs/rules/stories-export-typed.md) | Storybook's Stories should be typed | ✅ | | |
|
|
150
150
|
| [max-parent-import-depth](docs/rules/max-parent-import-depth.md) | Limit relative imports to a maximum parent depth. | ✅ | | |
|
|
151
|
+
| [ts-named-tuple-elements](docs/rules/ts-named-tuple-elements.md) | Enforce (or forbid) named tuple elements | ✅ | | |
|
|
151
152
|
|
|
152
153
|
## Code Reuse Policy
|
|
153
154
|
|
|
@@ -26,25 +26,20 @@ const rules = {
|
|
|
26
26
|
'test/**', // tape, common npm pattern
|
|
27
27
|
'tests/**', // also common npm pattern
|
|
28
28
|
'spec/**', // mocha, rspec-like pattern
|
|
29
|
+
'scripts/**', // custom infra scripts
|
|
29
30
|
'**/__tests__/**', // jest pattern
|
|
30
31
|
'**/__mocks__/**', // jest pattern
|
|
31
32
|
'test.{js,jsx}', // repos with a single test file
|
|
32
33
|
'test-*.{js,jsx}', // repos with multiple top-level test files
|
|
33
34
|
'**/*{.,_}{test,spec}.{js,jsx}', // tests where the extension or filename suffix denotes that it is a test
|
|
34
|
-
'**/jest.config.js', // jest config
|
|
35
35
|
'**/jest.setup.js', // jest setup
|
|
36
|
-
'**/vue.config.js', // vue-cli config
|
|
37
|
-
'**/webpack.config.js', // webpack config
|
|
38
|
-
'**/webpack.config.*.js', // webpack config
|
|
39
|
-
'**/rollup.config.js', // rollup config
|
|
40
|
-
'**/rollup.config.*.js', // rollup config
|
|
41
36
|
'**/gulpfile.js', // gulp config
|
|
42
37
|
'**/gulpfile.*.js', // gulp config
|
|
43
38
|
'**/Gruntfile{,.js}', // grunt config
|
|
44
|
-
'**/protractor.conf.js', // protractor config
|
|
45
|
-
'**/protractor.conf.*.js', // protractor config
|
|
46
|
-
'**/karma.conf.js', // karma config
|
|
47
39
|
'**/.eslintrc.js', // eslint config
|
|
40
|
+
'**/*.conf{,ig}.js', // any configs
|
|
41
|
+
'**/*.conf{,ig}.*.js', // any configs
|
|
42
|
+
'**/*.stories.jsx', // storybook stories
|
|
48
43
|
],
|
|
49
44
|
optionalDependencies: false,
|
|
50
45
|
},
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import ruleStoriesExportTyped from "./rules/stories-export-typed.js";
|
|
|
6
6
|
import ruleStrictObservableComponentsDeclaration from "./rules/strict-observable-components-declaration.js";
|
|
7
7
|
import ruleRequireObserver from "./rules/require-observer.js";
|
|
8
8
|
import ruleMaxParentImportDepth from "./rules/max-parent-import-depth.js";
|
|
9
|
+
import ruleTsNamedTupleElements from "./rules/ts-named-tuple-elements.js";
|
|
9
10
|
const plugin = {
|
|
10
11
|
meta: {
|
|
11
12
|
name: packageJson.name,
|
|
@@ -20,6 +21,7 @@ const plugin = {
|
|
|
20
21
|
'strict-observable-components-declaration': ruleStrictObservableComponentsDeclaration,
|
|
21
22
|
'require-observer': ruleRequireObserver,
|
|
22
23
|
'max-parent-import-depth': ruleMaxParentImportDepth,
|
|
24
|
+
'ts-named-tuple-elements': ruleTsNamedTupleElements,
|
|
23
25
|
},
|
|
24
26
|
};
|
|
25
27
|
export default plugin;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Enforce (or forbid) named tuple elements
|
|
4
|
+
* @author Sergey Kozlov
|
|
5
|
+
*/
|
|
6
|
+
type Options = [
|
|
7
|
+
mainOptions: {
|
|
8
|
+
mode?: 'always' | 'never';
|
|
9
|
+
}
|
|
10
|
+
];
|
|
11
|
+
type MessageIds = 'requireNames' | 'forbidNames';
|
|
12
|
+
declare const _default: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
export default ESLintUtils.RuleCreator(() => '')({
|
|
3
|
+
name: 'ts-named-tuple-elements',
|
|
4
|
+
defaultOptions: [{ mode: 'always' }],
|
|
5
|
+
meta: {
|
|
6
|
+
type: 'suggestion',
|
|
7
|
+
docs: {
|
|
8
|
+
description: 'Enforces consistent usage of named elements in TypeScript tuple types.',
|
|
9
|
+
},
|
|
10
|
+
messages: {
|
|
11
|
+
requireNames: 'Tuple elements must have names.',
|
|
12
|
+
forbidNames: 'Tuple elements must not have names.',
|
|
13
|
+
},
|
|
14
|
+
schema: [
|
|
15
|
+
{
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: {
|
|
18
|
+
mode: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
enum: ['always', 'never'],
|
|
21
|
+
default: 'always',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
create(context) {
|
|
28
|
+
const [options] = context.options;
|
|
29
|
+
const { mode = 'always' } = options ?? {};
|
|
30
|
+
switch (mode) {
|
|
31
|
+
case 'always':
|
|
32
|
+
return {
|
|
33
|
+
'TSTupleType > :not(TSNamedTupleMember)': node => {
|
|
34
|
+
context.report({ node, messageId: 'requireNames' });
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
case 'never':
|
|
38
|
+
return {
|
|
39
|
+
'TSTupleType > TSNamedTupleMember': node => {
|
|
40
|
+
context.report({ node, messageId: 'forbidNames' });
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
default:
|
|
44
|
+
throw new Error(`Invalig mode value: ${String(mode)}`);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Enforce (or forbid) named tuple elements (ts-named-tuple-elements)
|
|
2
|
+
|
|
3
|
+
Enforces consistent usage of named elements in TypeScript tuple types.
|
|
4
|
+
This rule helps improve readability, self-documentation, and maintainability of tuple types
|
|
5
|
+
by explicitly naming their elements instead of relying on positional meaning.
|
|
6
|
+
|
|
7
|
+
## Rule Details
|
|
8
|
+
|
|
9
|
+
Examples of **incorrect** code for this rule:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
type Location = [number, number]
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Examples of **correct** code for this rule:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
type Location = [lat: number, long: number]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Options
|
|
22
|
+
|
|
23
|
+
`mode`: `always` (by default) or `never`
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"@dartess/ts-named-tuple-elements": [
|
|
28
|
+
"error",
|
|
29
|
+
{
|
|
30
|
+
"mode": "never"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
When mode is "never", tuple elements should not have names.
|