Skip to content

Commit

Permalink
feat(rules): arrow-parens are always required
Browse files Browse the repository at this point in the history
To avoid mixing shorthand with longhand (the company's choice), this
rule will enforce always having parens around arrow function
parameters.

Semver: minor
Ref: LOG-8207
  • Loading branch information
darinspivey committed Dec 4, 2020
1 parent f912dc1 commit f14276f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
8 changes: 3 additions & 5 deletions eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
"accessor-pairs": 0,
"array-bracket-spacing": [2, "never"],
"array-callback-return": 2,
"arrow-parens": ["error", "as-needed", {
"requireForBlockBody": true
}],
"arrow-parens": ["error", "always"],
"block-scoped-var": 2,
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", {
Expand Down Expand Up @@ -221,7 +219,6 @@
"functionPrototypeMethods": false
}],
"yoda": 0,
"sensible/check-require": [2, "always"],
"logdna/grouped-require": 2,
"logdna/require-file-extension": 2,
"logdna/tap-consistent-assertions": [2, {
Expand All @@ -237,6 +234,7 @@
"notMatch": "notMatch",
"type": "type"
}
}]
}],
"sensible/check-require": [2, "always"]
}
}
31 changes: 30 additions & 1 deletion test/failures.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const MAX_LEN_CODE = path.join(__dirname, 'fixtures', 'max-len-fixture')
const LOGDNA_PLUGIN_CODE = path.join(__dirname, 'fixtures', 'logdna-plugin-fixture')

const readFile = fs.promises.readFile
test('invalid config', async (t) => {
test('Invalid linting for larger code blocks read from fixtures', async (t) => {
const cli = new CLIEngine({
useEslintrc: false
, cwd: __dirname
Expand Down Expand Up @@ -68,3 +68,32 @@ test('invalid config', async (t) => {
)
})
}).catch(threw)

test('Invlalid linting with quick-and-dirty inline code', async (t) => {
const cli = new CLIEngine({
useEslintrc: false
, cwd: __dirname
, configFile: '../eslintrc.json'
, rules: {
'strict': 'off'
, 'sensible/indent': 'off'
, 'eol-last': 'off'
, 'no-unused-vars': 'off'
}
})

t.test('arrow-parens', async (t) => {
const code = '[].map(thing => { return thing + 1 })'

const result = cli.executeOnText(code)
t.equal(result.errorCount, 1, 'error count')
const messages = result.results[0].messages

t.equal(messages[0].ruleId, 'arrow-parens', 'arrow-parens is the rule id')
t.equal(
messages[0].message
, 'Expected parentheses around arrow function argument.'
, 'Error message is correct'
)
})
})

0 comments on commit f14276f

Please sign in to comment.