Skip to content

Commit 8fd4dda

Browse files
committed
Improve code style
Closes #508
1 parent 3e958d0 commit 8fd4dda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+904
-524
lines changed

rules/catch-error-name.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ function isLintablePromiseCatch(node) {
2323

2424
const [firstArgument] = node.arguments;
2525

26-
return firstArgument.type === 'FunctionExpression' || firstArgument.type === 'ArrowFunctionExpression';
26+
return (
27+
firstArgument.type === 'FunctionExpression' ||
28+
firstArgument.type === 'ArrowFunctionExpression'
29+
);
2730
}
2831

2932
const create = context => {
30-
const {
31-
ecmaVersion
32-
} = context.parserOptions;
33+
const {ecmaVersion} = context.parserOptions;
3334

3435
const options = {
3536
name: 'error',
@@ -127,17 +128,19 @@ const create = context => {
127128
};
128129
};
129130

130-
const schema = [{
131-
type: 'object',
132-
properties: {
133-
name: {
134-
type: 'string'
135-
},
136-
caughtErrorsIgnorePattern: {
137-
type: 'string'
131+
const schema = [
132+
{
133+
type: 'object',
134+
properties: {
135+
name: {
136+
type: 'string'
137+
},
138+
caughtErrorsIgnorePattern: {
139+
type: 'string'
140+
}
138141
}
139142
}
140-
}];
143+
];
141144

142145
module.exports = {
143146
create,

rules/consistent-function-scoping.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ function checkReferences(scope, parent, scopeManager) {
4141
// This check looks for neighboring function definitions
4242
const hitIdentifier = variable.identifiers.some(identifier => {
4343
// Only look at identifiers that live in a FunctionDeclaration
44-
if (!identifier.parent || identifier.parent.type !== 'FunctionDeclaration') {
44+
if (
45+
!identifier.parent ||
46+
identifier.parent.type !== 'FunctionDeclaration'
47+
) {
4548
return false;
4649
}
4750

rules/custom-error-definition.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ const hasValidSuperClass = node => {
2929
return nameRegexp.test(name);
3030
};
3131

32-
const isSuperExpression = node => node.type === 'ExpressionStatement' && node.expression.type === 'CallExpression' && node.expression.callee.type === 'Super';
32+
const isSuperExpression = node =>
33+
node.type === 'ExpressionStatement' &&
34+
node.expression.type === 'CallExpression' &&
35+
node.expression.callee.type === 'Super';
3336

3437
const isAssignmentExpression = (node, name) => {
35-
if (node.type !== 'ExpressionStatement' || node.expression.type !== 'AssignmentExpression') {
38+
if (
39+
node.type !== 'ExpressionStatement' ||
40+
node.expression.type !== 'AssignmentExpression'
41+
) {
3642
return false;
3743
}
3844

rules/error-message.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ const findIdentifierValues = (identifierNode, context) => {
4242
};
4343

4444
const isEmptyMessageString = node => {
45-
return node.arguments.length > 0 && node.arguments[0].type === 'Literal' && !node.arguments[0].value;
45+
return (
46+
node.arguments.length > 0 &&
47+
node.arguments[0].type === 'Literal' &&
48+
!node.arguments[0].value
49+
);
4650
};
4751

4852
const reportError = (expressionNode, context) => {

rules/escape-case.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ const fix = (value, regexp) => {
1717
if (results) {
1818
const prefix = results[1].length + 1;
1919
const fixedEscape = results[2].slice(0, 1) + results[2].slice(1).toUpperCase();
20-
return value.slice(0, results.index + prefix) + fixedEscape + value.slice(results.index + results[0].length);
20+
return (
21+
value.slice(0, results.index + prefix) +
22+
fixedEscape +
23+
value.slice(results.index + results[0].length)
24+
);
2125
}
2226

2327
return value;
@@ -67,7 +71,11 @@ const fixRegExp = node => {
6771

6872
if (escapeNodePosition) {
6973
const [start, end] = escapeNodePosition;
70-
return raw.slice(0, start) + fix(raw.slice(start, end), escapePatternWithLowercase) + raw.slice(end, raw.length);
74+
return (
75+
raw.slice(0, start) +
76+
fix(raw.slice(start, end), escapePatternWithLowercase) +
77+
raw.slice(end, raw.length)
78+
);
7179
}
7280

7381
return raw;

rules/explicit-length-check.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ function checkNonZeroType(context, node, type) {
100100
}
101101

102102
function checkBinaryExpression(context, node, options) {
103-
if (node.right.type === 'Literal' &&
103+
if (
104+
node.right.type === 'Literal' &&
104105
node.left.type === 'MemberExpression' &&
105106
node.left.property.type === 'Identifier' &&
106107
node.left.property.name === 'length'
@@ -127,7 +128,8 @@ function checkExpression(context, node) {
127128
return;
128129
}
129130

130-
if (node.type === 'MemberExpression' &&
131+
if (
132+
node.type === 'MemberExpression' &&
131133
node.property.type === 'Identifier' &&
132134
node.property.name === 'length'
133135
) {
@@ -146,18 +148,16 @@ const create = context => {
146148
};
147149
};
148150

149-
const schema = [{
150-
type: 'object',
151-
properties: {
152-
'non-zero': {
153-
enum: [
154-
'not-equal',
155-
'greater-than',
156-
'greater-than-or-equal'
157-
]
151+
const schema = [
152+
{
153+
type: 'object',
154+
properties: {
155+
'non-zero': {
156+
enum: ['not-equal', 'greater-than', 'greater-than-or-equal']
157+
}
158158
}
159159
}
160-
}];
160+
];
161161

162162
module.exports = {
163163
create,

rules/filename-case.js

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,7 @@ const create = context => {
168168
return;
169169
}
170170

171-
const {
172-
leading,
173-
words
174-
} = splitFilename(filename);
171+
const {leading, words} = splitFilename(filename);
175172
const isValid = validateFilename(words, chosenCasesFunctions);
176173

177174
if (isValid) {
@@ -195,53 +192,55 @@ const create = context => {
195192
};
196193
};
197194

198-
const schema = [{
199-
oneOf: [
200-
{
201-
properties: {
202-
case: {
203-
enum: [
204-
'camelCase',
205-
'snakeCase',
206-
'kebabCase',
207-
'pascalCase'
208-
]
195+
const schema = [
196+
{
197+
oneOf: [
198+
{
199+
properties: {
200+
case: {
201+
enum: [
202+
'camelCase',
203+
'snakeCase',
204+
'kebabCase',
205+
'pascalCase'
206+
]
207+
},
208+
ignore: {
209+
type: 'array',
210+
uniqueItems: true
211+
}
209212
},
210-
ignore: {
211-
type: 'array',
212-
uniqueItems: true
213-
}
213+
additionalProperties: false
214214
},
215-
additionalProperties: false
216-
},
217-
{
218-
properties: {
219-
cases: {
220-
properties: {
221-
camelCase: {
222-
type: 'boolean'
223-
},
224-
snakeCase: {
225-
type: 'boolean'
226-
},
227-
kebabCase: {
228-
type: 'boolean'
215+
{
216+
properties: {
217+
cases: {
218+
properties: {
219+
camelCase: {
220+
type: 'boolean'
221+
},
222+
snakeCase: {
223+
type: 'boolean'
224+
},
225+
kebabCase: {
226+
type: 'boolean'
227+
},
228+
pascalCase: {
229+
type: 'boolean'
230+
}
229231
},
230-
pascalCase: {
231-
type: 'boolean'
232-
}
232+
additionalProperties: false
233233
},
234-
additionalProperties: false
234+
ignore: {
235+
type: 'array',
236+
uniqueItems: true
237+
}
235238
},
236-
ignore: {
237-
type: 'array',
238-
uniqueItems: true
239-
}
240-
},
241-
additionalProperties: false
242-
}
243-
]
244-
}];
239+
additionalProperties: false
240+
}
241+
]
242+
}
243+
];
245244

246245
module.exports = {
247246
create,

rules/import-index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,18 @@ const create = context => {
2929
return rules;
3030
};
3131

32-
const schema = [{
33-
type: 'object',
34-
properties: {
35-
ignoreImports: {
36-
type: 'boolean',
37-
default: false
38-
}
39-
},
40-
additionalProperties: false
41-
}];
32+
const schema = [
33+
{
34+
type: 'object',
35+
properties: {
36+
ignoreImports: {
37+
type: 'boolean',
38+
default: false
39+
}
40+
},
41+
additionalProperties: false
42+
}
43+
];
4244

4345
module.exports = {
4446
create,

rules/no-array-instanceof.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ const getDocumentationUrl = require('./utils/get-documentation-url');
33

44
const create = context => ({
55
BinaryExpression: node => {
6-
if (node.operator === 'instanceof' && node.right.type === 'Identifier' && node.right.name === 'Array') {
6+
if (
7+
node.operator === 'instanceof' &&
8+
node.right.type === 'Identifier' &&
9+
node.right.name === 'Array'
10+
) {
711
// Get the source code and extract the left part
8-
const arraySourceCode = context.getSourceCode().text.slice(node.left.range[0], node.left.range[1]);
12+
const arraySourceCode = context
13+
.getSourceCode()
14+
.text.slice(node.left.range[0], node.left.range[1]);
915

1016
context.report({
1117
node,

rules/no-console-spaces.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ const getConsoleMethod = node => {
2626
const getArgumentValue = (context, nodeArgument) => {
2727
let value = null;
2828

29-
if (nodeArgument.type === 'Literal' && typeof nodeArgument.value === 'string') {
29+
if (
30+
nodeArgument.type === 'Literal' &&
31+
typeof nodeArgument.value === 'string'
32+
) {
3033
value = nodeArgument.value;
3134
}
3235

@@ -69,13 +72,11 @@ const fixValue = (value, {
6972
};
7073

7174
const getFixableArguments = (context, node) => {
72-
const {
73-
arguments: arguments_
74-
} = node;
75+
const {arguments: arguments_} = node;
7576

7677
const fixables = arguments_.map((nodeArgument, i) => {
7778
const fixLeading = i !== 0;
78-
const fixTrailing = i !== (arguments_.length - 1);
79+
const fixTrailing = i !== arguments_.length - 1;
7980

8081
const value = getArgumentValue(context, nodeArgument);
8182
const fixed = fixValue(value, {fixLeading, fixTrailing});
@@ -92,10 +93,7 @@ const getFixableArguments = (context, node) => {
9293
};
9394

9495
const fixArgument = (context, fixable, fixer) => {
95-
const {
96-
nodeArgument,
97-
fixed
98-
} = fixable;
96+
const {nodeArgument, fixed} = fixable;
9997

10098
// Ignore quotes and backticks
10199
const range = [

0 commit comments

Comments
 (0)