-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules.js
51 lines (44 loc) · 1.22 KB
/
rules.js
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
/** @type {{ [key: string]: import('eslint').Rule.RuleModule }} */
exports.rules = {
'no-const': {
meta: {
type: 'suggestion',
fixable: 'code',
messages: {
unexpectedConst: 'Unexpected const, use let instead.',
},
},
create: (ctx) => {
let sourceCode = ctx.getSourceCode()
return {
/** @param {import('estree').VariableDeclaration} node */
'VariableDeclaration:exit'(node) {
if (node.kind !== 'const') {
return
}
// @ts-ignore
if (node.parent?.type == 'ExportNamedDeclaration') {
return
}
// @ts-ignore
if (!node.parent?.parent) {
return
}
if (node.loc) {
let { start } = node.loc
let end = { ...start, column: start.column + 5 }
node.loc = { start, end }
}
ctx.report({
node,
messageId: 'unexpectedConst',
fix(fixer) {
let token = sourceCode.getFirstToken(node, { filter: (t) => t.value === 'const' })
return token ? fixer.replaceText(token, 'let') : null
},
})
},
}
},
},
}