@firefoxic/eslint-config 6.0.0 → 7.0.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/lib/enough-is-enough/index.js +18 -0
- package/lib/enough-is-enough/no-multiline-named-imports/index.js +53 -0
- package/lib/enough-is-enough/no-single-quotes-in-imports-and-object-keys/index.js +79 -0
- package/lib/enough-is-enough/prefer-let/index.js +74 -0
- package/lib/index.js +1 -9
- package/package.json +9 -8
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import noMultilineNamedImports from "./no-multiline-named-imports/index.js"
|
|
2
|
+
import noSingleQuotesInImportsAndObjectKeys from "./no-single-quotes-in-imports-and-object-keys/index.js"
|
|
3
|
+
import preferLet from "./prefer-let/index.js"
|
|
4
|
+
|
|
5
|
+
const plugin = {
|
|
6
|
+
// preferred location of name and version
|
|
7
|
+
meta: {
|
|
8
|
+
name: `eslint-plugin-enough-is-enough`,
|
|
9
|
+
namespace: `enough-is-enough`,
|
|
10
|
+
},
|
|
11
|
+
rules: {
|
|
12
|
+
"no-multiline-named-imports": noMultilineNamedImports,
|
|
13
|
+
"no-single-quotes-in-imports-and-object-keys": noSingleQuotesInImportsAndObjectKeys,
|
|
14
|
+
"prefer-let": preferLet,
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default plugin
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
meta: {
|
|
3
|
+
type: `layout`,
|
|
4
|
+
fixable: `code`,
|
|
5
|
+
messages: {
|
|
6
|
+
multiline: `Multi-line named imports are disallowed.`,
|
|
7
|
+
},
|
|
8
|
+
},
|
|
9
|
+
create (context) {
|
|
10
|
+
let sourceCode = context.sourceCode
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
ImportDeclaration (node) {
|
|
14
|
+
let namedSpecifiers = node.specifiers.filter((s) => s.type === `ImportSpecifier`)
|
|
15
|
+
|
|
16
|
+
if (namedSpecifiers.length === 0) return
|
|
17
|
+
|
|
18
|
+
let tokens = sourceCode.getTokens(node)
|
|
19
|
+
let openBrace = tokens.find((t) => t.value === `{`)
|
|
20
|
+
let closeBrace = tokens.reverse().find((t) => t.value === `}`)
|
|
21
|
+
|
|
22
|
+
if (!openBrace || !closeBrace) return
|
|
23
|
+
|
|
24
|
+
if (openBrace.loc.start.line !== closeBrace.loc.end.line) {
|
|
25
|
+
context.report({
|
|
26
|
+
node,
|
|
27
|
+
messageId: `multiline`,
|
|
28
|
+
fix (fixer) {
|
|
29
|
+
let imports = namedSpecifiers.map((s) => sourceCode.getText(s)).join(`, `)
|
|
30
|
+
let defaultImport = node.specifiers.find((s) => s.type === `ImportDefaultSpecifier`)
|
|
31
|
+
let namespaceImport = node.specifiers.find((s) => s.type === `ImportNamespaceSpecifier`)
|
|
32
|
+
let source = sourceCode.getText(node.source)
|
|
33
|
+
|
|
34
|
+
let newImport = `import `
|
|
35
|
+
|
|
36
|
+
if (defaultImport) newImport += `${sourceCode.getText(defaultImport)}, `
|
|
37
|
+
if (namespaceImport) newImport += `${sourceCode.getText(namespaceImport)}, `
|
|
38
|
+
newImport += `{ ${imports} } from ${source}`
|
|
39
|
+
|
|
40
|
+
let lastToken = sourceCode.getLastToken(node)
|
|
41
|
+
let hasSemicolon = lastToken && lastToken.value === `;`
|
|
42
|
+
|
|
43
|
+
if (hasSemicolon) newImport += `;`
|
|
44
|
+
|
|
45
|
+
return fixer.replaceText(node, newImport)
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
meta: {
|
|
3
|
+
type: `suggestion`,
|
|
4
|
+
docs: { description: `Disallow single quotes in import/export sources and object keys when quoted` },
|
|
5
|
+
fixable: `code`,
|
|
6
|
+
schema: [],
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
create (context) {
|
|
10
|
+
let sourceCode = context.sourceCode
|
|
11
|
+
|
|
12
|
+
function isSingleQuoted (node) {
|
|
13
|
+
if (typeof node.value !== `string`) return false
|
|
14
|
+
|
|
15
|
+
let text = sourceCode.getText(node)
|
|
16
|
+
|
|
17
|
+
return text.startsWith(`'`) && text.endsWith(`'`)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function checkLiteralInImportOrExport (node) {
|
|
21
|
+
if (!node.source) return
|
|
22
|
+
|
|
23
|
+
let literal = node.source
|
|
24
|
+
|
|
25
|
+
if (isSingleQuoted(literal)) {
|
|
26
|
+
context.report({
|
|
27
|
+
node: literal,
|
|
28
|
+
message: `Use double quotes for import/export source.`,
|
|
29
|
+
fix (fixer) {
|
|
30
|
+
let newText = `"${literal.value.replace(/"/g, `\\"`)}"`
|
|
31
|
+
|
|
32
|
+
return fixer.replaceText(literal, newText)
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function checkObjectExpression (node) {
|
|
39
|
+
let properties = node.properties
|
|
40
|
+
|
|
41
|
+
let hasQuotedKey = properties.some(
|
|
42
|
+
(prop) => prop.type === `Property`
|
|
43
|
+
&& prop.key.type === `Literal`
|
|
44
|
+
&& typeof prop.key.value === `string`,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
if (!hasQuotedKey) return
|
|
48
|
+
|
|
49
|
+
for (let prop of properties) {
|
|
50
|
+
if (
|
|
51
|
+
prop.type !== `Property`
|
|
52
|
+
|| prop.key.type !== `Literal`
|
|
53
|
+
|| typeof prop.key.value !== `string`
|
|
54
|
+
) continue
|
|
55
|
+
|
|
56
|
+
let key = prop.key
|
|
57
|
+
|
|
58
|
+
if (isSingleQuoted(key)) {
|
|
59
|
+
context.report({
|
|
60
|
+
node: key,
|
|
61
|
+
message: `Use double quotes for quoted object keys.`,
|
|
62
|
+
fix (fixer) {
|
|
63
|
+
let newText = `"${key.value.replace(/"/g, `\\"`)}"`
|
|
64
|
+
|
|
65
|
+
return fixer.replaceText(key, newText)
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
ImportDeclaration: checkLiteralInImportOrExport,
|
|
74
|
+
ExportNamedDeclaration: checkLiteralInImportOrExport,
|
|
75
|
+
ExportAllDeclaration: checkLiteralInImportOrExport,
|
|
76
|
+
ObjectExpression: checkObjectExpression,
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Use `let` declarations to bind names to values
|
|
3
|
+
* @author Charles Lowell
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
meta: {
|
|
8
|
+
docs: {
|
|
9
|
+
description: `Use "let" declarations to bind names to values`,
|
|
10
|
+
category: `Stylistic Issues`,
|
|
11
|
+
recommended: false,
|
|
12
|
+
},
|
|
13
|
+
fixable: `code`, // or "code" or "whitespace"
|
|
14
|
+
schema: [], // fill in your schema
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
create (context) {
|
|
18
|
+
let sourceCode = context.sourceCode ?? context.getSourceCode()
|
|
19
|
+
|
|
20
|
+
function getScope (node) {
|
|
21
|
+
return sourceCode.getScope ? sourceCode.getScope(node) : context.getScope()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isGlobalScope (node) {
|
|
25
|
+
return getScope(node).type === `global`
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isModuleScope (node) {
|
|
29
|
+
return getScope(node).type === `module`
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isProgramScope (node) {
|
|
33
|
+
return getScope(node).block.type === `Program`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isTopLevelScope (node) {
|
|
37
|
+
return isGlobalScope(node) || isModuleScope(node) || isProgramScope(node)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function isInAmbientContext (node) {
|
|
41
|
+
let current = node.parent
|
|
42
|
+
while (current) {
|
|
43
|
+
if (current.type === `TSModuleDeclaration` && current.declare === true) return true
|
|
44
|
+
|
|
45
|
+
current = current.parent
|
|
46
|
+
}
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
VariableDeclaration (node) {
|
|
52
|
+
if (node.kind === `var`) {
|
|
53
|
+
if (isInAmbientContext(node)) return
|
|
54
|
+
|
|
55
|
+
context.report({
|
|
56
|
+
message: `prefer "let" over "var" to declare value bindings`,
|
|
57
|
+
node,
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
else if (node.kind === `const` && !isTopLevelScope(node)) {
|
|
61
|
+
let constToken = sourceCode.getFirstToken(node)
|
|
62
|
+
|
|
63
|
+
context.report({
|
|
64
|
+
message: `"const" declaration outside top-level scope`,
|
|
65
|
+
node,
|
|
66
|
+
fix (fixer) {
|
|
67
|
+
return fixer.replaceText(constToken, `let`)
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import stylistic from "@stylistic/eslint-plugin"
|
|
2
|
-
import eslintPluginPreferLet from "eslint-plugin-prefer-let"
|
|
3
2
|
import eslintPluginSimpleImportSort from "eslint-plugin-simple-import-sort"
|
|
4
3
|
|
|
5
4
|
import enoughIsEnough from "./enough-is-enough/index.js"
|
|
@@ -130,14 +129,6 @@ export default [
|
|
|
130
129
|
"valid-typeof": `error`,
|
|
131
130
|
},
|
|
132
131
|
},
|
|
133
|
-
{
|
|
134
|
-
plugins: {
|
|
135
|
-
"prefer-let": eslintPluginPreferLet,
|
|
136
|
-
},
|
|
137
|
-
rules: {
|
|
138
|
-
"prefer-let/prefer-let": `error`,
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
132
|
{
|
|
142
133
|
plugins: {
|
|
143
134
|
"simple-import-sort": eslintPluginSimpleImportSort,
|
|
@@ -426,6 +417,7 @@ export default [
|
|
|
426
417
|
rules: {
|
|
427
418
|
"enough-is-enough/no-multiline-named-imports": `error`,
|
|
428
419
|
"enough-is-enough/no-single-quotes-in-imports-and-object-keys": `error`,
|
|
420
|
+
"enough-is-enough/prefer-let": `error`,
|
|
429
421
|
},
|
|
430
422
|
},
|
|
431
423
|
]
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firefoxic/eslint-config",
|
|
3
3
|
"description": "Shared config for eslint by firefoxic.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Sergey Artemov",
|
|
@@ -24,24 +24,25 @@
|
|
|
24
24
|
"types": "./lib/index.d.ts"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
|
-
"./lib
|
|
28
|
-
"./lib
|
|
27
|
+
"./lib/**/*.d.ts",
|
|
28
|
+
"./lib/**/*.js",
|
|
29
|
+
"!**/*.test.js"
|
|
29
30
|
],
|
|
30
31
|
"peerDependencies": {
|
|
31
|
-
"eslint": "^
|
|
32
|
+
"eslint": "^10.0.0"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@stylistic/eslint-plugin": "^5.7.
|
|
35
|
-
"eslint-plugin-prefer-let": "^4.0.1",
|
|
35
|
+
"@stylistic/eslint-plugin": "^5.7.1",
|
|
36
36
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
37
|
-
"globals": "^17.
|
|
37
|
+
"globals": "^17.3.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"help": "make help",
|
|
41
41
|
"eslint": "eslint"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"eslint": "^
|
|
44
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
45
|
+
"eslint": "^10.0.0"
|
|
45
46
|
},
|
|
46
47
|
"keywords": [
|
|
47
48
|
"config",
|