-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheslint.config.mjs
More file actions
102 lines (92 loc) · 3.59 KB
/
Copy patheslint.config.mjs
File metadata and controls
102 lines (92 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// @ts-check
import js from "@eslint/js";
import globals from "globals";
import tseslint from "typescript-eslint";
import eslintPluginPrettier from "eslint-plugin-prettier";
import eslintConfigPrettier from "eslint-config-prettier";
const internalNamingPlugin = {
rules: {
"underscore-prefix": {
meta: {
type: "problem",
schema: [],
messages: {
missingPrefix: 'API "{{name}}" is marked @internal and must start with an underscore.',
},
},
create(context) {
const sourceCode = context.sourceCode;
return {
"Program:exit"() {
for (const comment of sourceCode.getAllComments()) {
if (!/@internal\b/u.test(comment.value)) {
continue;
}
const token = sourceCode.getTokenAfter(comment);
let node = token === null ? null : sourceCode.getNodeByRangeIndex(token.range[0]);
if (node?.type === "ExportNamedDeclaration") {
node = node.declaration;
}
while (node !== null) {
if (node.type === "MethodDefinition" && node.kind === "constructor") {
break;
}
const nameNode =
"id" in node && node.id?.type === "Identifier"
? node.id
: "key" in node && node.key?.type === "Identifier"
? node.key
: node.type === "TSParameterProperty" && node.parameter.type === "Identifier"
? node.parameter
: null;
if (nameNode !== null) {
if (!nameNode.name.startsWith("_")) {
context.report({ node: nameNode, messageId: "missingPrefix", data: { name: nameNode.name } });
}
break;
}
node = node.parent;
}
}
},
};
},
},
},
};
export default tseslint.config(
{
ignores: ["dist/**", "node_modules/**", "test-results/**", "docs/**", "**/*.md"],
},
js.configs.recommended,
eslintConfigPrettier,
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
parser: tseslint.parser,
parserOptions: {
sourceType: "module",
ecmaVersion: 2022,
},
},
plugins: {
internalNaming: internalNamingPlugin,
prettier: eslintPluginPrettier,
},
rules: {
"internalNaming/underscore-prefix": "error",
"prettier/prettier": "error",
},
},
{
files: ["**/*.ts"],
extends: [tseslint.configs.recommended],
rules: {
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
},
}
);