Skip to content

Commit aeaa3cd

Browse files
feat(eslint): add rule for curly braces (#7761)
* feat(eslint): add rule for curly braces * chore(project): run eslint and prettier Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent f759a06 commit aeaa3cd

File tree

13 files changed

+79
-22
lines changed

13 files changed

+79
-22
lines changed

config/eslint-config-carbon/base.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99

1010
module.exports = {
1111
parser: 'babel-eslint',
12-
extends: ['eslint:recommended', require.resolve('./plugins/jsdoc')],
12+
extends: [
13+
'eslint:recommended',
14+
require.resolve('./rules/best-practices'),
15+
require.resolve('./plugins/jsdoc'),
16+
],
1317
rules: {
1418
// Handle cases where we are destructuring but may not be using the initial
1519
// variables
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright IBM Corp. 2018, 2018
3+
*
4+
* This source code is licensed under the Apache-2.0 license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
module.exports = {
11+
rules: {
12+
// @see https://eslint.org/docs/rules/curly
13+
curly: 'error',
14+
},
15+
};

packages/cli/src/commands/sassdoc/tools.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ function createAnchorLink(name, heading) {
122122
function createMarkdownItem(item) {
123123
let str = '';
124124

125-
if (!item.context) return '';
125+
if (!item.context) {
126+
return '';
127+
}
126128

127129
let status = item.access === 'public' ? '✅' : '❌';
128130

@@ -160,9 +162,13 @@ $${item.context.name}: ${item.context.value};
160162

161163
if (item.parameter) {
162164
item.parameter.forEach((param) => {
163-
if (paramStr) paramStr += `, `;
165+
if (paramStr) {
166+
paramStr += `, `;
167+
}
164168
paramStr += `$${param.name}`;
165-
if (param.default) paramStr += `: ${param.default}`;
169+
if (param.default) {
170+
paramStr += `: ${param.default}`;
171+
}
166172
});
167173
}
168174

packages/components/gulpfile.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ const convertToESMGulpPlugin = () =>
241241
}),
242242
],
243243
onwarn: (warning, handle) => {
244-
if (warning.code !== 'EMPTY_BUNDLE') handle(warning);
244+
if (warning.code !== 'EMPTY_BUNDLE') {
245+
handle(warning);
246+
}
245247
},
246248
})
247249
.then((bundle) => bundle.generate({ format: 'esm' }))

packages/components/tests/pure-modules-test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ describe('ES modules', () => {
7171
terser.terser(),
7272
],
7373
onwarn: (warning, handle) => {
74-
if (warning.code !== 'EMPTY_BUNDLE') handle(warning);
74+
if (warning.code !== 'EMPTY_BUNDLE') {
75+
handle(warning);
76+
}
7577
},
7678
treeshake: {
7779
annotations: false,
@@ -103,7 +105,9 @@ describe('ES modules', () => {
103105
terser.terser(),
104106
],
105107
onwarn: (warning, handle) => {
106-
if (warning.code !== 'EMPTY_BUNDLE') handle(warning);
108+
if (warning.code !== 'EMPTY_BUNDLE') {
109+
handle(warning);
110+
}
107111
},
108112
treeshake: {
109113
annotations: false,

packages/icon-build-helpers/src/builders/plugins/virtual.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ module.exports = function virtual(modules) {
2222
name: 'virtual',
2323

2424
resolveId(id, importer) {
25-
if (id in modules) return PREFIX + id;
25+
if (id in modules) {
26+
return PREFIX + id;
27+
}
2628

2729
if (importer) {
28-
if (importer.startsWith(PREFIX))
30+
if (importer.startsWith(PREFIX)) {
2931
importer = importer.slice(PREFIX.length);
32+
}
3033
const resolved = path.resolve(path.dirname(importer), id);
31-
if (resolvedIds.has(resolved)) return PREFIX + resolved;
34+
if (resolvedIds.has(resolved)) {
35+
return PREFIX + resolved;
36+
}
3237
}
3338
},
3439

packages/react/src/components/DataTable/tools/filter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export const defaultFilterRows = ({
2828
rowIds.filter((rowId) =>
2929
headers.some(({ key }) => {
3030
const id = getCellId(rowId, key);
31-
if (typeof cellsById[id].value === 'boolean') return false;
31+
if (typeof cellsById[id].value === 'boolean') {
32+
return false;
33+
}
3234
return ('' + cellsById[id].value)
3335
.toLowerCase()
3436
.includes(inputValue.toLowerCase());

packages/react/src/components/DatePicker/DatePicker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ const carbonFlatpickrMonthSelectPlugin = (config) => (fp) => {
5555
return;
5656
}
5757
fp.monthElements.forEach((elem) => {
58-
if (!elem.parentNode) return;
58+
if (!elem.parentNode) {
59+
return;
60+
}
5961
elem.parentNode.removeChild(elem);
6062
});
6163
fp.monthElements.splice(

packages/react/src/components/MultiSelect/FilterableMultiSelect.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,15 @@ export default class FilterableMultiSelect extends React.Component {
221221
this.setState({
222222
highlightedIndex: changes.highlightedIndex,
223223
});
224-
if (!this.state.isOpen) this.handleOnMenuChange(true);
224+
if (!this.state.isOpen) {
225+
this.handleOnMenuChange(true);
226+
}
225227
break;
226228
case Downshift.stateChangeTypes.keyDownEscape:
227229
case Downshift.stateChangeTypes.mouseUp:
228-
if (this.state.isOpen) this.handleOnMenuChange(false);
230+
if (this.state.isOpen) {
231+
this.handleOnMenuChange(false);
232+
}
229233
break;
230234
// Opt-in to some cases where we should be toggling the menu based on
231235
// a given key press or mouse handler
@@ -240,8 +244,9 @@ export default class FilterableMultiSelect extends React.Component {
240244
nextIsOpen = true;
241245
}
242246
}
243-
if (this.state.isOpen !== nextIsOpen)
247+
if (this.state.isOpen !== nextIsOpen) {
244248
this.handleOnMenuChange(nextIsOpen);
249+
}
245250
break;
246251
}
247252
}
@@ -263,8 +268,9 @@ export default class FilterableMultiSelect extends React.Component {
263268
inputValue: inputValue || '',
264269
};
265270
});
266-
if (Boolean(inputValue) !== this.state.isOpen)
271+
if (Boolean(inputValue) !== this.state.isOpen) {
267272
this.handleOnMenuChange(Boolean(inputValue));
273+
}
268274
}
269275
};
270276

packages/react/src/components/MultiSelect/MultiSelect-story.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ export const WithChangeOnClose = withReadme(readme, () => {
225225
const [hasFocus, setHasFocus] = useState(false);
226226
const [active, setActive] = useState(false);
227227
const [selItems, setSelItems] = useState([items[0]]);
228-
if (!hasFocus && active && selItems.length == 0) setActive(false);
228+
if (!hasFocus && active && selItems.length == 0) {
229+
setActive(false);
230+
}
229231

230232
return (
231233
<div style={{ width: 300 }}>
@@ -234,7 +236,9 @@ export const WithChangeOnClose = withReadme(readme, () => {
234236
checked={active}
235237
onChange={(a) => {
236238
setActive(a);
237-
if (a) setSelItems([items[0]]);
239+
if (a) {
240+
setSelItems([items[0]]);
241+
}
238242
}}
239243
labelText="Active"
240244
/>

0 commit comments

Comments
 (0)