Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit e9af962

Browse files
committed
First rule types
1 parent c2dce49 commit e9af962

File tree

13 files changed

+273
-109
lines changed

13 files changed

+273
-109
lines changed

.eslintrc.js

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// @ts-check
2+
const { defineConfig } = require('eslint-define-config');
3+
4+
module.exports = defineConfig({
5+
env: {
6+
es6: true,
7+
node: true
8+
},
9+
extends: [
10+
'eslint:recommended',
11+
'plugin:@typescript-eslint/recommended',
12+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
13+
'plugin:jsdoc/recommended',
14+
'plugin:prettier/recommended'
15+
],
16+
parser: '@typescript-eslint/parser',
17+
parserOptions: {
18+
project: ['./tsconfig.lint.json'],
19+
warnOnUnsupportedTypeScriptVersion: false
20+
},
21+
plugins: ['@typescript-eslint', 'prettier', 'jsdoc', 'spellcheck', 'inclusive-language'],
22+
rules: {
23+
curly: ['error'],
24+
'linebreak-style': ['error', 'unix'],
25+
'no-case-declarations': 'warn',
26+
quotes: ['error', 'single', { avoidEscape: true }],
27+
semi: ['error', 'always'],
28+
29+
'@typescript-eslint/ban-ts-comment': 'off',
30+
'@typescript-eslint/explicit-function-return-type': ['error', { allowExpressions: true }],
31+
'@typescript-eslint/indent': ['error', 2, { SwitchCase: 1, ignoredNodes: ['MemberExpression'] }],
32+
'@typescript-eslint/interface-name-prefix': 'off',
33+
'@typescript-eslint/member-ordering': 'warn',
34+
'@typescript-eslint/no-explicit-any': 'off',
35+
'@typescript-eslint/no-inferrable-types': 'off',
36+
'@typescript-eslint/no-parameter-properties': 'off',
37+
'@typescript-eslint/no-unsafe-assignment': 'off',
38+
'@typescript-eslint/no-unused-vars': 'off',
39+
'@typescript-eslint/prefer-nullish-coalescing': 'warn',
40+
'@typescript-eslint/prefer-optional-chain': 'warn',
41+
'@typescript-eslint/prefer-readonly': ['warn'],
42+
'@typescript-eslint/restrict-template-expressions': 'off',
43+
'@typescript-eslint/typedef': ['warn', { memberVariableDeclaration: true, variableDeclaration: true }],
44+
45+
'jsdoc/match-description': [
46+
'warn',
47+
{
48+
mainDescription: '/^[A-Z`].+?(\\.|:)(\\n\\n.*((\\n{1,2}- .+)|(_.+_)|`.+`|\\n\\n---))?$/us',
49+
matchDescription: '^[A-Z`].+(\\.|`.+`)$',
50+
contexts: ['any'],
51+
tags: {
52+
param: true,
53+
returns: true
54+
}
55+
}
56+
],
57+
'jsdoc/no-types': 'error',
58+
'jsdoc/require-jsdoc': [
59+
'warn',
60+
{
61+
contexts: [
62+
'ClassDeclaration',
63+
"ClassProperty:not([accessibility='private'])",
64+
'ExportNamedDeclaration:has(VariableDeclaration)',
65+
'FunctionExpression',
66+
"MethodDefinition:not([accessibility='private']) > FunctionExpression",
67+
'TSEnumDeclaration',
68+
'TSInterfaceDeclaration',
69+
'TSMethodSignature',
70+
// 'TSPropertySignature',
71+
'TSTypeAliasDeclaration'
72+
]
73+
}
74+
],
75+
'jsdoc/require-param-type': 'off',
76+
'jsdoc/require-returns-type': 'off',
77+
78+
'spellcheck/spell-checker': [
79+
'warn',
80+
{
81+
minLength: 3,
82+
skipWords: ['backtick', 'backticks', 'ecma']
83+
}
84+
],
85+
86+
'inclusive-language/use-inclusive-words': [
87+
'warn',
88+
{
89+
allowedTerms: [
90+
{
91+
term: '/master',
92+
allowPartialMatches: true
93+
}
94+
],
95+
words: [
96+
{
97+
word: 'guys',
98+
suggestions: ['folks']
99+
}
100+
]
101+
}
102+
]
103+
},
104+
settings: {
105+
jsdoc: {
106+
mode: 'typescript'
107+
}
108+
}
109+
});

.eslintrc.json

Lines changed: 0 additions & 106 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"cSpell.words": ["Quadflieg", "readonly", "typeof"],
2+
"cSpell.words": ["Quadflieg", "backticks", "readonly", "typeof"],
33
"eslint.validate": ["javascript", "typescript"],
44
"typescript.tsdk": "node_modules/typescript/lib"
55
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@typescript-eslint/parser": "~4.19.0",
3939
"eslint": "~7.22.0",
4040
"eslint-config-prettier": "~8.1.0",
41+
"eslint-define-config": "~1.0.0-alpha.1",
4142
"eslint-plugin-inclusive-language": "~2.1.1",
4243
"eslint-plugin-jsdoc": "~32.3.0",
4344
"eslint-plugin-prettier": "~3.3.1",

src/index.ts

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,74 @@
1+
import { EslintRules } from './rules/eslint';
2+
import { RuleConfig } from './rules/rule-config';
3+
4+
/**
5+
*
6+
*/
7+
export interface Env {
8+
es6?: boolean;
9+
node?: boolean;
10+
}
11+
12+
/**
13+
*
14+
*/
15+
export interface ParserOptions {
16+
sourceType?: 'module' | '...';
17+
ecmaVersion?: 2020;
18+
project?: any;
19+
warnOnUnsupportedTypeScriptVersion?: boolean;
20+
}
21+
22+
/**
23+
*
24+
*/
25+
export type Rules = Partial<EslintRules> & Partial<Record<string, RuleConfig>>;
26+
27+
/**
28+
*
29+
*/
30+
export interface Override {
31+
files: string[];
32+
rules: Rules;
33+
}
34+
35+
/**
36+
*
37+
*/
38+
export type Overrides = Array<Override>;
39+
40+
/**
41+
*
42+
*/
43+
export interface Settings {
44+
jsdoc?: {
45+
mode: string;
46+
};
47+
}
48+
49+
/**
50+
*
51+
*/
52+
export interface EslintConfig {
53+
root?: boolean;
54+
env?: Env;
55+
extends?: string[];
56+
parser?: string;
57+
parserOptions?: ParserOptions;
58+
plugins?: string[];
59+
rules?: Rules;
60+
overrides?: Overrides;
61+
settings?: Settings;
62+
}
63+
164
/**
265
* Define an eslint config.
366
*
467
* @param config Eslint config.
568
* @returns Eslint config.
669
*/
770
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
8-
export function defineConfig(config: any) {
71+
export function defineConfig(config: EslintConfig) {
972
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
1073
return config;
1174
}

src/rules/eslint/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NoDebuggerRule } from './no-debugger';
2+
import { QuotesRule } from './quotes';
3+
import { SemiRule } from './semi';
4+
5+
/**
6+
*
7+
*/
8+
export type EslintRules = NoDebuggerRule & QuotesRule & SemiRule;

src/rules/eslint/no-debugger.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
*
5+
*/
6+
export type NoDebuggerRuleConfig = RuleConfig<[]>;
7+
8+
/**
9+
*
10+
*/
11+
export interface NoDebuggerRule {
12+
/**
13+
* Disallow the use of debugger.
14+
*
15+
* @see [no-debugger](https://eslint.org/docs/rules/no-debugger)
16+
*/
17+
'no-debugger': NoDebuggerRuleConfig;
18+
}

src/rules/eslint/quotes.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
*
5+
*/
6+
export type QuotesOption = 'double' | 'single' | 'backtick';
7+
8+
/**
9+
*
10+
*/
11+
export interface QuotesConfig {
12+
/**
13+
* Allows strings to use single-quotes or double-quotes so long as the string contains a quote that would have to be escaped otherwise.
14+
*/
15+
avoidEscape?: boolean;
16+
/**
17+
* Allows strings to use backticks.
18+
*/
19+
allowTemplateLiterals?: boolean;
20+
}
21+
22+
/**
23+
*
24+
*/
25+
export type QuotesRuleConfig = RuleConfig<[QuotesOption, QuotesConfig]>;
26+
27+
/**
28+
*
29+
*/
30+
export interface QuotesRule {
31+
/**
32+
* Enforce the consistent use of either backticks, double, or single quotes.
33+
*
34+
* @see [quotes](https://eslint.org/docs/rules/quotes)
35+
*/
36+
quotes: QuotesRuleConfig;
37+
}

src/rules/eslint/semi.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
*
5+
*/
6+
export type SemiRuleConfig = RuleConfig<['always' | 'never' /* ... */]>;
7+
8+
/**
9+
*
10+
*/
11+
export interface SemiRule {
12+
/**
13+
* Require or disallow semicolons instead of ASI.
14+
*
15+
* @see [semi](https://eslint.org/docs/rules/semi)
16+
*/
17+
semi: SemiRuleConfig;
18+
}

src/rules/rule-config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { RuleSeverity } from './rule-severity';
2+
3+
/**
4+
*
5+
*/
6+
export type RuleConfig<Options extends unknown[] = unknown[]> = RuleSeverity | [RuleSeverity, ...Options];

0 commit comments

Comments
 (0)