Skip to content

Commit

Permalink
⚒ update eslintrc (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea authored Nov 29, 2020
1 parent 3d5938e commit 729c016
Show file tree
Hide file tree
Showing 29 changed files with 102 additions and 97 deletions.
6 changes: 0 additions & 6 deletions .eslintignore

This file was deleted.

19 changes: 9 additions & 10 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
extends:
- plugin:@mysticatea/es2015
- plugin:@mysticatea/es2020
- plugin:@mysticatea/+eslint-plugin

ignorePatterns:
- /.nyc_output
- /coverage
- /node_modules
- "!.vuepress"
- /docs/.vuepress/dist

overrides:
- files: lib/rules/*.js
- files: lib/rules/**/*.js
rules:
"@mysticatea/eslint-plugin/require-meta-docs-url":
- error
- pattern: http://mysticatea.github.io/eslint-plugin-es/rules/{{name}}.html

- files: scripts/*.js
rules:
require-jsdoc: off

- files: "*.vue"
parserOptions:
parser: babel-eslint
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
os: ubuntu-latest
# On the minimum supported ESLint/Node.js version
- eslint: 4
node: 8.10
node: "8.10"
os: ubuntu-latest

runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion docs/.vuepress/components/eslint-playground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default {
cookedCode() {
return (this.code || "").replace(
/&#x([0-9a-zA-Z]+);/gu,
(_, codePoint) => String.fromCodePoint(parseInt(codePoint, 16))
(_, codePoint) => String.fromCodePoint(parseInt(codePoint, 16)),
)
},
},
Expand Down
5 changes: 4 additions & 1 deletion docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ module.exports = {
docsBranch: "master",
editLinks: true,

nav: [{ text: "Guide", link: "/" }, { text: "Rules", link: "/rules/" }],
nav: [
{ text: "Guide", link: "/" },
{ text: "Rules", link: "/rules/" },
],

sidebarDepth: 0,
sidebar: [
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-accessor-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
create(context) {
return {
"Property[kind='get'], Property[kind='set'], MethodDefinition[kind='get'], MethodDefinition[kind='set']"(
node
node,
) {
context.report({ node, messageId: "forbidden" })
},
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/no-arrow-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ module.exports = {
const paramText = params.length
? sourceCode.text.slice(
params[0].range[0],
params[params.length - 1].range[1]
params[params.length - 1].range[1],
)
: ""

const arrowToken = sourceCode.getTokenBefore(
node.body,
isArrowToken
isArrowToken,
)
const preText = sourceCode.text.slice(
arrowToken.range[1],
node.body.range[0]
node.body.range[0],
)
const bodyText = sourceCode.text
.slice(arrowToken.range[1], node.range[1])
Expand Down Expand Up @@ -96,7 +96,7 @@ module.exports = {
}
return fixer.replaceText(
node,
toFunctionExpression(node, hasThis)
toFunctionExpression(node, hasThis),
)
},
})
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-block-scoped-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
create(context) {
return {
"VariableDeclaration[kind='const'], VariableDeclaration[kind='let']"(
node
node,
) {
context.report({ node, messageId: "forbidden" })
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-destructuring.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
create(context) {
return {
":matches(:function, AssignmentExpression, VariableDeclarator, :function > :matches(AssignmentPattern, RestElement), ForInStatement, ForOfStatement) > :matches(ArrayPattern, ObjectPattern)"(
node
node,
) {
context.report({ node, messageId: "forbidden" })
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-exponential-operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
create(context) {
return {
"AssignmentExpression[operator='**='], BinaryExpression[operator='**']"(
node
node,
) {
context.report({ node, messageId: "forbidden" })
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-json-superset.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
fix(fixer) {
return fixer.replaceTextRange(
[offset + index, offset + index + 1],
`\\u${code}`
`\\u${code}`,
)
},
})
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-logical-assignment-operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ module.exports = {
fixer.replaceText(operatorToken, newOperator),
fixer.insertTextAfter(
operatorToken,
` ${varText} ${biOperator}`
` ${varText} ${biOperator}`,
),
]
if (!utils.isParenthesized(node.right, sourceCode)) {
results.push(
fixer.insertTextBefore(node.right, "("),
fixer.insertTextAfter(node.right, ")")
fixer.insertTextAfter(node.right, ")"),
)
}
return results
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
create(context) {
return {
"ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration, ImportDeclaration"(
node
node,
) {
context.report({ node, messageId: "forbidden" })
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-numeric-separators.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
fix: fixer =>
fixer.replaceText(
node,
removeNumericSeparators(node.raw)
removeNumericSeparators(node.raw),
),
})
}
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-optional-chaining.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
context.report({
node: sourceCode.getTokenAfter(
node.callee,
isQuestionDotToken
isQuestionDotToken,
),
messageId: "forbidden",
})
Expand All @@ -51,7 +51,7 @@ module.exports = {
context.report({
node: sourceCode.getTokenAfter(
node.object,
isQuestionDotToken
isQuestionDotToken,
),
messageId: "forbidden",
})
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/no-property-shorthands.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = {
: sourceCode.getLastToken(node.key)
const keyText = sourceCode.text.slice(
firstKeyToken.range[0],
lastKeyToken.range[1]
lastKeyToken.range[1],
)
let functionHeader = "function"

Expand All @@ -53,13 +53,13 @@ module.exports = {

return fixer.replaceTextRange(
[node.range[0], lastKeyToken.range[1]],
`${keyText}: ${functionHeader}`
`${keyText}: ${functionHeader}`,
)
}

return {
"ObjectExpression > :matches(Property[method=true], Property[shorthand=true])"(
node
node,
) {
context.report({
node,
Expand All @@ -69,7 +69,7 @@ module.exports = {
: fixer =>
fixer.insertTextAfter(
node.key,
`: ${node.key.name}`
`: ${node.key.name}`,
),
})
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-spread-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
create(context) {
return {
":matches(ArrayExpression, CallExpression, NewExpression) > SpreadElement"(
node
node,
) {
context.report({ node, messageId: "forbidden" })
},
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-template-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = {
const sourceCode = context.getSourceCode()
return {
"TaggedTemplateExpression, :not(TaggedTemplateExpression) > TemplateLiteral"(
node
node,
) {
context.report({
node,
Expand All @@ -74,8 +74,8 @@ module.exports = {
node,
templateLiteralToStringConcat(
node,
sourceCode
)
sourceCode,
),
)
: undefined,
})
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-trailing-commas.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
const sourceCode = context.getSourceCode()
return {
"ArrayExpression, ArrayPattern, ObjectExpression, ObjectPattern"(
node
node,
) {
const token = sourceCode.getLastToken(node, 1)
if (isCommaToken(token)) {
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-unicode-codepoint-escapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const { definePatternSearchGenerator } = require("../utils")
const codePointEscapeSearchGenerator = definePatternSearchGenerator(
/\\u\{[0-9a-fA-F]+\}/gu
/\\u\{[0-9a-fA-F]+\}/gu,
)

/**
Expand Down Expand Up @@ -71,12 +71,12 @@ module.exports = {
const highSurrogate = (codePoint >> 10) + 0xd800
const lowSurrogate = (codePoint % 0x400) + 0xdc00
replacement = `${toHex(highSurrogate)}\\u${toHex(
lowSurrogate
lowSurrogate,
)}`
}
return fixer.replaceTextRange(
[range[0] + 2, range[1]],
replacement
replacement,
)
},
})
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = {
{
type: "DeprecationWarning",
code: "ESLINT_PLUGIN_ES_LEGACY_CONFIG",
}
},
)
},
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"@mysticatea/eslint-plugin": "^13.0.0",
"@vuepress/plugin-pwa": "^1.2.0",
"acorn": "^7.1.0",
"babel-eslint": "^10.0.1",
"codecov": "3.7.0",
"eslint": "^7.10.0",
"eslint4b": "^7.10.0",
Expand Down
13 changes: 7 additions & 6 deletions scripts/new-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const logger = console
process.exitCode = 1
return
}
if (!/^[\w-]+$/u.test(ruleId)) {
if (!/^(?:aggressive\/)?[a-z0-9-]+$/u.test(ruleId)) {
logger.error("Invalid RuleID '%s'.", ruleId)
process.exitCode = 1
return
Expand Down Expand Up @@ -53,7 +53,7 @@ module.exports = {
return {}
},
}
`
`,
)
fs.writeFileSync(
testFile,
Expand All @@ -66,7 +66,7 @@ module.exports = {
const RuleTester = require("../../tester")
const rule = require("../../../lib/rules/${ruleId}.js")
if (!RuleTester.isSupported(2020)) {
if (!RuleTester.isSupported(2021)) {
//eslint-disable-next-line no-console
console.log("Skip the tests of ${ruleId}.")
return
Expand All @@ -76,11 +76,12 @@ new RuleTester().run("${ruleId}", rule, {
valid: [],
invalid: [],
})
`
`,
)
fs.writeFileSync(
docFile,
`# (es/${ruleId})
`# es/${ruleId}
>
This rule reports ??? as errors.
Expand All @@ -91,7 +92,7 @@ This rule reports ??? as errors.
<eslint-playground type="bad" code="/*eslint es/${ruleId}: error */
" />
`
`,
)

cp.execSync(`code "${ruleFile}"`)
Expand Down
Loading

0 comments on commit 729c016

Please sign in to comment.