Repository navigation
Expand file tree
/
Copy patheslint.config.js
More file actions
69 lines (67 loc) · 2.1 KB
/
Copy patheslint.config.js
File metadata and controls
69 lines (67 loc) · 2.1 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
import tsParser from '@typescript-eslint/parser';
import vitest from '@vitest/eslint-plugin';
// Bare `#NNN` refs in comments aren't clickable and rot as the code moves. Matches `#` and 2+ digits outside a URL
// fragment or identifier.
const noBareIssueRefs = {
meta: {
type: 'suggestion',
docs: { description: 'Disallow bare #NNN issue references in comments; use a full URL or drop it.' },
messages: {
bareRef:
"Bare issue reference '{{ref}}' in a comment — link it as a full URL (…/issues/{{num}}) or drop it; git history is the canonical trace.",
},
},
create(context) {
const sourceCode = context.sourceCode ?? context.getSourceCode();
const pattern = /(?<![\w/])#(\d{2,})\b/g;
return {
Program() {
for (const comment of sourceCode.getAllComments()) {
for (const match of comment.value.matchAll(pattern)) {
context.report({ loc: comment.loc, messageId: 'bareRef', data: { ref: match[0], num: match[1] } });
}
}
},
};
},
};
export default [
{
ignores: ['**/dist/**/*', '**/coverage/**/*', '**/out/**/*', '**/.turbo/**/*'],
},
{
// Production sources only: test comments reference mock issue/PR numbers, which aren't citations.
files: ['packages/**/src/**/*.ts'],
languageOptions: {
parser: tsParser,
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
},
plugins: {
local: { rules: { 'no-bare-issue-refs': noBareIssueRefs } },
},
rules: {
'local/no-bare-issue-refs': 'error',
},
},
{
files: ['packages/**/test/**/*.spec.ts', 'packages/**/test/**/*.test.ts'],
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaVersion: 'latest',
project: './tsconfig.base.json',
},
},
plugins: {
vitest,
},
rules: {
...vitest.configs.recommended.rules,
'vitest/prefer-called-exactly-once-with': 'off',
'vitest/valid-title': [
'error',
{ mustMatch: { it: '^should', test: '^should' }, mustNotMatch: { it: '#\\d', test: '#\\d' } },
],
},
},
];