Skip to content

Commit 498f43e

Browse files
committed
Format files with prettier
1 parent 3144b5f commit 498f43e

24 files changed

+139
-132
lines changed

bin/npm-check-github-package-requirements.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@ const path = require('path')
55

66
const checks = []
77
function check(name, callback) {
8-
checks.push([checks.length+1, name, callback])
8+
checks.push([checks.length + 1, name, callback])
99
}
1010

1111
function run() {
1212
process.stdout.write(`1..${checks.length}\n`)
1313
checks.forEach(([count, name, callback]) => {
14-
Promise.resolve().then(callback).then(() => {
15-
process.stdout.write(`ok ${count} - ${name}\n`)
16-
}).catch(error => {
17-
process.stdout.write(`not ok ${count} - ${name}\n ${error}\n`)
18-
})
14+
Promise.resolve()
15+
.then(callback)
16+
.then(() => {
17+
process.stdout.write(`ok ${count} - ${name}\n`)
18+
})
19+
.catch(error => {
20+
process.stdout.write(`not ok ${count} - ${name}\n ${error}\n`)
21+
})
1922
})
2023
}
2124

22-
2325
const packageRoot = process.argv[2]
2426

2527
check('package.json exists', () => {

lib/configs/browser.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
module.exports = {
2-
'env': {
3-
'browser': true
2+
env: {
3+
browser: true
44
},
5-
'plugins': [
6-
'github'
7-
],
8-
'rules': {
5+
plugins: ['github'],
6+
rules: {
97
'github/async-preventdefault': 'error',
108
'github/authenticity-token': 'error',
119
'github/js-class-name': 'error',

lib/configs/es6.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
module.exports = {
2-
'parserOptions': {
3-
'ecmaFeatures': {
4-
'ecmaVersion': 6
2+
parserOptions: {
3+
ecmaFeatures: {
4+
ecmaVersion: 6
55
},
6-
'sourceType': 'module'
6+
sourceType: 'module'
77
},
8-
'env': {
9-
'es6': true
8+
env: {
9+
es6: true
1010
},
11-
'plugins': [
12-
'github',
13-
'import'
14-
],
15-
'rules': {
11+
plugins: ['github', 'import'],
12+
rules: {
1613
'github/array-foreach': 'error',
1714
'github/no-then': 'error',
1815
'import/default': 'error',

lib/configs/flow.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
module.exports = {
2-
'parser': 'babel-eslint',
3-
'plugins': [
4-
'flowtype',
5-
'github'
6-
],
7-
'rules': {
2+
parser: 'babel-eslint',
3+
plugins: ['flowtype', 'github'],
4+
rules: {
85
'flowtype/define-flow-type': 'error',
9-
'flowtype/require-valid-file-annotation': ['error', 'always', {'annotationStyle': 'block'}],
6+
'flowtype/require-valid-file-annotation': ['error', 'always', {annotationStyle: 'block'}],
107
'flowtype/use-flow-type': 'error',
118
'github/no-flow-weak': 'error',
129
'github/no-flowfixme': 'error',

lib/configs/react.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
module.exports = {
2-
'parser': 'babel-eslint',
3-
'parserOptions': {
4-
'ecmaFeatures': {
5-
'jsx': true
2+
parser: 'babel-eslint',
3+
parserOptions: {
4+
ecmaFeatures: {
5+
jsx: true
66
}
77
},
8-
'plugins': [
9-
'react'
10-
],
11-
'rules': {
12-
'func-style': ['error', 'declaration', {'allowArrowFunctions': true}],
8+
plugins: ['react'],
9+
rules: {
10+
'func-style': ['error', 'declaration', {allowArrowFunctions: true}],
1311
'react/jsx-boolean-value': 'error',
1412
'react/jsx-handler-names': 'error',
1513
'react/jsx-key': 'error',
@@ -28,7 +26,7 @@ module.exports = {
2826
'react/no-direct-mutation-state': 'error',
2927
'react/no-find-dom-node': 'error',
3028
'react/no-is-mounted': 'error',
31-
'react/no-multi-comp': ['error', {'ignoreStateless': true}],
29+
'react/no-multi-comp': ['error', {ignoreStateless: true}],
3230
'react/no-render-return-value': 'error',
3331
'react/no-string-refs': 'error',
3432
'react/no-unknown-property': 'error',

lib/configs/recommended.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
module.exports = {
2-
'plugins': [
3-
'github',
4-
'prettier'
5-
],
6-
'rules': {
7-
'camelcase': ['error', {'properties': 'always'}],
2+
plugins: ['github', 'prettier'],
3+
rules: {
4+
camelcase: ['error', {properties: 'always'}],
85
'constructor-super': 'error',
9-
'eqeqeq': ['error', 'smart'],
6+
eqeqeq: ['error', 'smart'],
107
'func-style': ['error', 'declaration'],
118
'github/no-implicit-buggy-globals': 'error',
129
'github/no-sprockets-directives': 'error',
@@ -56,7 +53,7 @@ module.exports = {
5653
'no-unused-labels': 'error',
5754
'no-unused-vars': 'error',
5855
'no-useless-escape': 'error',
59-
'object-shorthand': ['error', 'always', {'avoidQuotes': true}],
56+
'object-shorthand': ['error', 'always', {avoidQuotes: true}],
6057
'prefer-promise-reject-errors': 'error',
6158
'prettier/prettier': 'error',
6259
'require-yield': 'error',

lib/formatters/stylish-fixes.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,16 @@ module.exports = function(results) {
4949

5050
if (total > 0) {
5151
output += [
52-
'\u2716 ', total, pluralize(' problem', total),
53-
' (', errors, pluralize(' error', errors), ', ',
54-
warnings, pluralize(' warning', warnings), ')\n'
52+
'\u2716 ',
53+
total,
54+
pluralize(' problem', total),
55+
' (',
56+
errors,
57+
pluralize(' error', errors),
58+
', ',
59+
warnings,
60+
pluralize(' warning', warnings),
61+
')\n'
5562
].join('')
5663
}
5764

@@ -68,5 +75,8 @@ function diff(a, b) {
6875
fs.writeFileSync(aPath, a, {encoding: 'utf8'})
6976
fs.writeFileSync(bPath, b, {encoding: 'utf8'})
7077
const result = childProcess.spawnSync('diff', ['-U5', aPath, bPath], {encoding: 'utf8'})
71-
return result.stdout.split('\n').slice(2).join('\n')
78+
return result.stdout
79+
.split('\n')
80+
.slice(2)
81+
.join('\n')
7282
}

lib/rules/array-foreach.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = function(context) {
22
return {
3-
'CallExpression': function(node) {
3+
CallExpression(node) {
44
if (node.callee.property && node.callee.property.name === 'forEach') {
55
context.report(node, 'Prefer for...of instead of Array.forEach')
66
}

lib/rules/authenticity-token.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
module.exports = function(context) {
22
function checkAuthenticityTokenUsage(node, str) {
33
if (str.includes('authenticity_token')) {
4-
context.report(node, 'Form CSRF tokens (authenticity tokens) should not be created in JavaScript and their values should not be used directly for XHR requests.')
4+
context.report(
5+
node,
6+
'Form CSRF tokens (authenticity tokens) should not be created in JavaScript and their values should not be used directly for XHR requests.'
7+
)
58
}
69
}
710

811
return {
9-
'Literal': function(node) {
12+
Literal(node) {
1013
if (typeof node.value === 'string') {
1114
checkAuthenticityTokenUsage(node, node.value)
1215
}

lib/rules/js-class-name.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ module.exports = function(context) {
1919
}
2020

2121
return {
22-
'Literal': function(node) {
22+
Literal(node) {
2323
if (typeof node.value === 'string') {
2424
checkStringFormat(node, node.value)
2525

26-
if (node.parent &&
27-
node.parent.type === 'BinaryExpression' &&
28-
node.parent.operator === '+' &&
29-
node.parent.left.value) {
26+
if (
27+
node.parent &&
28+
node.parent.type === 'BinaryExpression' &&
29+
node.parent.operator === '+' &&
30+
node.parent.left.value
31+
) {
3032
checkStringEndsWithJSClassName(node.parent.left, node.parent.left.value)
3133
}
3234
}
3335
},
34-
'TemplateLiteral': function(node) {
36+
TemplateLiteral(node) {
3537
node.quasis.forEach(function(quasi) {
3638
checkStringFormat(quasi, quasi.value.raw)
3739

lib/rules/no-dataset.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = function(context) {
22
return {
3-
'MemberExpression': function(node) {
3+
MemberExpression(node) {
44
if (node.property && node.property.name === 'dataset') {
5-
context.report(node, 'Use getAttribute(\'data-your-attribute\') instead of dataset.')
5+
context.report(node, "Use getAttribute('data-your-attribute') instead of dataset.")
66
}
77
}
88
}

lib/rules/no-flow-weak.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ module.exports = function(context) {
22
function handleComment(comment) {
33
var value = comment.value.trim()
44
if (value.match(/@flow weak/)) {
5-
context.report(comment, 'Do not use Flow \'weak\' mode checking, use @flow instead.')
5+
context.report(comment, "Do not use Flow 'weak' mode checking, use @flow instead.")
66
}
77
}
88

99
return {
10-
'LineComment': handleComment,
11-
'BlockComment': handleComment,
12-
'Program': function() {
10+
LineComment: handleComment,
11+
BlockComment: handleComment,
12+
Program() {
1313
const comments = context.getSourceCode().getAllComments()
1414
comments.forEach(handleComment)
1515
}

lib/rules/no-flowfixme.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ module.exports = function(context) {
22
function handleComment(comment) {
33
var value = comment.value.trim()
44
if (value.match(/\$FlowFixMe/)) {
5-
context.report(comment, 'Files with $FlowFixMe comments must also include /* eslint-disable github/no-flowfixme */')
5+
context.report(
6+
comment,
7+
'Files with $FlowFixMe comments must also include /* eslint-disable github/no-flowfixme */'
8+
)
69
}
710
}
811

912
return {
10-
'LineComment': handleComment,
11-
'BlockComment': handleComment,
12-
'Program': function() {
13+
LineComment: handleComment,
14+
BlockComment: handleComment,
15+
Program() {
1316
const comments = context.getSourceCode().getAllComments()
1417
comments.forEach(handleComment)
1518
}

lib/rules/no-implicit-buggy-globals.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = function(context) {
22
return {
3-
'Program': function() {
3+
Program() {
44
var scope = context.getScope()
55

66
scope.variables.forEach(function(variable) {
@@ -9,9 +9,12 @@ module.exports = function(context) {
99
}
1010

1111
variable.defs.forEach(function(def) {
12-
if (def.type === 'FunctionName' || def.type === 'ClassName' ||
13-
def.type === 'Variable' && def.parent.kind === 'const' ||
14-
def.type === 'Variable' && def.parent.kind === 'let') {
12+
if (
13+
def.type === 'FunctionName' ||
14+
def.type === 'ClassName' ||
15+
(def.type === 'Variable' && def.parent.kind === 'const') ||
16+
(def.type === 'Variable' && def.parent.kind === 'let')
17+
) {
1518
context.report(def.node, 'Implicit global variable, assign as global property instead.')
1619
}
1720
})

lib/rules/no-noflow.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ module.exports = function(context) {
77
}
88

99
return {
10-
'LineComment': handleComment,
11-
'BlockComment': handleComment,
12-
'Program': function() {
10+
LineComment: handleComment,
11+
BlockComment: handleComment,
12+
Program() {
1313
const comments = context.getSourceCode().getAllComments()
1414
comments.forEach(handleComment)
1515
}

lib/rules/no-sprockets-directives.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ module.exports = function(context) {
66
}
77

88
return {
9-
'LineComment': checkSprocketsDirectives,
10-
'BlockComment': checkSprocketsDirectives,
11-
'Program': function() {
9+
LineComment: checkSprocketsDirectives,
10+
BlockComment: checkSprocketsDirectives,
11+
Program() {
1212
const comments = context.getSourceCode().getAllComments()
1313
comments.forEach(checkSprocketsDirectives)
1414
}

lib/rules/no-unused-disabled-rules.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ module.exports = function(context) {
5252
}
5353

5454
return {
55-
'LineComment': handleComment,
56-
'BlockComment': handleComment,
55+
LineComment: handleComment,
56+
BlockComment: handleComment,
5757
'Program:exit': function(program) {
5858
const comments = context.getSourceCode().getAllComments()
5959
comments.forEach(handleComment)
@@ -63,7 +63,7 @@ module.exports = function(context) {
6363
if (value.ruleId) {
6464
context.report(value.comment, `Disabled '${value.ruleId}' rule, but didn't report anything.`)
6565
} else {
66-
context.report(program, 'Disabled all rules, but didn\'t report anything.')
66+
context.report(program, "Disabled all rules, but didn't report anything.")
6767
}
6868
}
6969
})

tests/authenticity-token.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,31 @@ ruleTester.run('authenticity-token', rule, {
77
valid: [],
88
invalid: [
99
{
10-
code: 'document.querySelector(\'form\').elements[\'authenticity_token\'].value',
10+
code: "document.querySelector('form').elements['authenticity_token'].value",
1111
errors: [
1212
{
13-
message: 'Form CSRF tokens (authenticity tokens) should not be created in JavaScript and their values should not be used directly for XHR requests.',
13+
message:
14+
'Form CSRF tokens (authenticity tokens) should not be created in JavaScript and their values should not be used directly for XHR requests.',
1415
type: 'Literal'
1516
}
1617
]
1718
},
1819
{
19-
code: 'document.querySelector(\'input[name=authenticity_token]\').value',
20+
code: "document.querySelector('input[name=authenticity_token]').value",
2021
errors: [
2122
{
22-
message: 'Form CSRF tokens (authenticity tokens) should not be created in JavaScript and their values should not be used directly for XHR requests.',
23+
message:
24+
'Form CSRF tokens (authenticity tokens) should not be created in JavaScript and their values should not be used directly for XHR requests.',
2325
type: 'Literal'
2426
}
2527
]
2628
},
2729
{
28-
code: '(new FormData()).append(\'authenticity_token\', \'asdf\')',
30+
code: "(new FormData()).append('authenticity_token', 'asdf')",
2931
errors: [
3032
{
31-
message: 'Form CSRF tokens (authenticity tokens) should not be created in JavaScript and their values should not be used directly for XHR requests.',
33+
message:
34+
'Form CSRF tokens (authenticity tokens) should not be created in JavaScript and their values should not be used directly for XHR requests.',
3235
type: 'Literal'
3336
}
3437
]

0 commit comments

Comments
 (0)