Skip to content

Commit 0d072ea

Browse files
mturleyredallen
authored andcommitted
Add tslint-plugin-prettier and apply code formatting (patternfly#2810)
* Reconfigure TSLint and add tslint-plugin-prettier * Add prettier-ignore where we need to use @ts-ignore on a long line * Run `yarn lint:ts --fix` and `yarn prettier` on all existing code
1 parent af0c7aa commit 0d072ea

File tree

648 files changed

+6367
-5262
lines changed

Some content is hidden

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

648 files changed

+6367
-5262
lines changed

.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package.json
2+
packages/**/dist/**/*.js
3+
packages/**/.cache/**/*.js
4+
scripts/generators/**/templates/**/*.js

.prettierrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"tabWidth": 2,
5+
"trailingComma": "none",
6+
"useTabs": false,
7+
"printWidth": 120
8+
}

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"minimist": "^1.2.0",
6363
"mutation-observer": "^1.0.3",
6464
"plop": "^2.0.0",
65+
"prettier": "^1.18.2",
6566
"react": "^16.4.0",
6667
"react-dom": "^16.4.0",
6768
"sass-loader": "^6.0.6",
@@ -71,6 +72,8 @@
7172
"stylelint-config-standard": "^18.2.0",
7273
"ts-jest": "24.1.0",
7374
"tslint": "^5.12.0",
75+
"tslint-config-prettier": "^1.18.0",
76+
"tslint-plugin-prettier": "^2.0.1",
7477
"tslint-react": "^3.6.0"
7578
},
7679
"scripts": {
@@ -88,6 +91,7 @@
8891
"lint:style": "stylelint \"**/sass/**/*.scss\" \"!**/dist/**/*.scss\"",
8992
"lint:ts": "node --max-old-space-size=4096 node_modules/.bin/tslint --project ./tslint.config.json --config tslint.json",
9093
"lint:versions": "node ./packages/patternfly-4/verifyCoreVersions.js",
94+
"prettier": "node node_modules/.bin/prettier --write \"storybook/**/*.{js,ts,tsx}\" \"packages/**/*.{js,ts,tsx}\" \"scripts/**/*.{js,ts,tsx}\"",
9195
"start": "yarn start:pf3",
9296
"start:cypress": "lerna run cypress:open",
9397
"start:demo-app": "lerna run start:demo-app --stream",

packages/patternfly-3/patternfly-react-extensions/src/components/CatalogTile/CatalogTile.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ class CatalogTile extends React.Component {
4242
}
4343

4444
this.descFullHeight = ref.clientHeight;
45-
}
45+
};
4646

4747
handleDescriptionSpanRef = ref => {
4848
if (!ref) {
4949
return;
5050
}
5151

5252
this.descLineHeight = parseInt(window.getComputedStyle(ref).getPropertyValue('line-height'), 10);
53-
}
53+
};
5454

5555
handleClick = e => {
5656
const { onClick, href } = this.props;
@@ -61,7 +61,7 @@ class CatalogTile extends React.Component {
6161
if (onClick) {
6262
onClick(e);
6363
}
64-
}
64+
};
6565

6666
renderBadges = badges => {
6767
if (!badges || !badges.length) {
@@ -75,7 +75,7 @@ class CatalogTile extends React.Component {
7575
))}
7676
</div>
7777
);
78-
}
78+
};
7979

8080
render() {
8181
const {

packages/patternfly-3/patternfly-react-extensions/src/components/CatalogTileView/CatalogTileViewCategory.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ class CatalogTileViewCategory extends React.Component {
5555
const rightSpacerWidth = this.categoryContainer.clientWidth % 235;
5656
this.setState({ numShown, rightSpacerWidth });
5757
}
58-
}
58+
};
5959

6060
handleRef = ref => {
6161
if (!ref) {
6262
return;
6363
}
6464
this.categoryContainer = ref;
65-
}
65+
};
6666

6767
render() {
6868
const { children, className, title, totalItems, viewAllText, viewAll, onViewAll, ...props } = this.props;

packages/patternfly-3/patternfly-react-extensions/src/components/CatalogTileView/__mocks__/mockCatalogTileViewExample.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class MockCatalogTileViewExample extends React.Component {
1717

1818
onViewAll = id => {
1919
this.setState({ showAll: id });
20-
}
20+
};
2121

2222
getBadges = item => {
2323
const badges = [];
@@ -39,13 +39,13 @@ class MockCatalogTileViewExample extends React.Component {
3939
}
4040

4141
return badges;
42-
}
42+
};
4343

4444
renderEmptyState = category => (
4545
<EmptyState className="blank-slate-content-pf">
4646
<EmptyState.Info>There are no items in this category.</EmptyState.Info>
4747
</EmptyState>
48-
)
48+
);
4949

5050
renderCategory = category => {
5151
const { showAll } = this.state;
@@ -80,7 +80,7 @@ class MockCatalogTileViewExample extends React.Component {
8080
}
8181

8282
return null;
83-
}
83+
};
8484

8585
render() {
8686
const { showAll } = this.state;

packages/patternfly-3/patternfly-react-extensions/src/components/DiffView/DiffView.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ const DiffView = ({
3434
const files = parseDiff(gitDiff);
3535
const hunk = files[0].hunks;
3636

37-
if (hunk.length === 0) { return emptyState; }
37+
if (hunk.length === 0) {
38+
return emptyState;
39+
}
3840
return hunk && <Diff className={classes} hunks={hunk} markEdits={markEdits} viewType={viewType} {...props} />;
3941
}
4042

@@ -53,7 +55,9 @@ const DiffView = ({
5355
/>
5456
);
5557

56-
if (patch === '') { return emptyState; }
58+
if (patch === '') {
59+
return emptyState;
60+
}
5761
return <div>{files.map(renderFile)}</div>;
5862
};
5963

packages/patternfly-3/patternfly-react-extensions/src/components/FilterSidePanel/_mocks_/mockFilterSidePanelExample.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ class MockFilterSidePanelExample extends React.Component {
5252
const showAllCategories = { ...this.state.showAllCategories };
5353
showAllCategories[id] = !showAllCategories[id];
5454
this.setState({ showAllCategories });
55-
}
55+
};
5656

5757
onFilterChange = (id, value) => {
5858
const activeFilters = { ...this.state.activeFilters };
5959
activeFilters[id] = value;
6060
this.setState({ activeFilters });
61-
}
61+
};
6262

6363
getStars = count => {
6464
const stars = [];
@@ -73,7 +73,7 @@ class MockFilterSidePanelExample extends React.Component {
7373
{stars}
7474
</span>
7575
);
76-
}
76+
};
7777

7878
render() {
7979
const { activeFilters, showAllCategories } = this.state;
@@ -259,7 +259,7 @@ class MockFilterSidePanelExample extends React.Component {
259259
checked={activeFilters.paymentDinersClub}
260260
onChange={e => this.onFilterChange('paymentDinersClub', e.target.checked)}
261261
>
262-
{'Diner\'s Club'}
262+
{"Diner's Club"}
263263
</FilterSidePanel.CategoryItem>
264264
</FilterSidePanel.Category>
265265
<FilterSidePanel.Category
@@ -301,7 +301,9 @@ class MockFilterSidePanelExample extends React.Component {
301301
count={8}
302302
checked={activeFilters.mileage10}
303303
onChange={e => this.onFilterChange('mileage10', e.target.checked)}
304-
>{'< 20'}</FilterSidePanel.CategoryItem>
304+
>
305+
{'< 20'}
306+
</FilterSidePanel.CategoryItem>
305307
</FilterSidePanel.Category>
306308
<FilterSidePanel.Category
307309
title="Rating"

packages/patternfly-3/patternfly-react-extensions/src/components/Select/SelectHelper.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export const createItemProps = (item, selectedItem, className, onItemClick) => {
77
active: selectedItem.id === item.id
88
};
99

10-
if (item.disabled) { return { ...itemProps, disabled: true }; }
10+
if (item.disabled) {
11+
return { ...itemProps, disabled: true };
12+
}
1113
return { ...itemProps, onClick: e => onItemClick({ e, id: item.id, name: item.name }) };
1214
};

packages/patternfly-3/patternfly-react-extensions/src/components/Select/SelectInput.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class SelectInput extends React.Component {
1111
}
1212

1313
componentDidMount() {
14-
if (this.props.focus) { this.searchInput.current.focus(); }
14+
if (this.props.focus) {
15+
this.searchInput.current.focus();
16+
}
1517
}
1618

1719
render() {

packages/patternfly-3/patternfly-react-extensions/src/components/Select/StatefulWrapperSelect.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ class StatefulWrapperSelect extends Component {
2020
const { options } = this.state;
2121
const results = [];
2222
options.forEach(opt => {
23-
if (opt.name.includes(search)) { results.push(opt); }
23+
if (opt.name.includes(search)) {
24+
results.push(opt);
25+
}
2426
});
2527
return results;
26-
}
28+
};
2729

2830
onSearch = e => {
2931
e.persist();
@@ -43,17 +45,21 @@ class StatefulWrapperSelect extends Component {
4345
}, 700);
4446
}
4547
);
46-
} else { this.setState({ isSearching: false, searchValue: '' }); }
47-
}
48+
} else {
49+
this.setState({ isSearching: false, searchValue: '' });
50+
}
51+
};
4852

4953
onClear = () => this.setState({ searchValue: '', isSearching: false });
5054

5155
onItemClick = host =>
52-
this.setState({ selected: { id: host.id, name: host.name }, open: false, isSearching: false, searchValue: '' })
56+
this.setState({ selected: { id: host.id, name: host.name }, open: false, isSearching: false, searchValue: '' });
5357

5458
handleClickOutside = () => {
55-
if (this.state.open === true) { this.onToggle(); }
56-
}
59+
if (this.state.open === true) {
60+
this.onToggle();
61+
}
62+
};
5763

5864
render() {
5965
const { open, isSearching, searchValue, selected, isLoading, options, matched } = this.state;

packages/patternfly-3/patternfly-react-extensions/src/components/TableGrid/_mocks_/mockTableGridExample.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ class MockTableGridExample extends React.Component {
5656
});
5757

5858
this.setState({ items, sortField: id, isAscending: updateAscending });
59-
}
59+
};
6060

6161
onSelect = (item, field) => {
6262
this.setState({ selectedItem: item, selectedField: field });
63-
}
63+
};
6464

6565
toggleSelection = item => {
6666
const { selectedItems } = this.state;
@@ -73,12 +73,12 @@ class MockTableGridExample extends React.Component {
7373
newSelections = [...selectedItems, item];
7474
}
7575
this.setState({ selectedItems: newSelections });
76-
}
76+
};
7777

7878
toggleAllSelections = () => {
7979
const { items, selectedItems } = this.state;
8080
this.setState({ selectedItems: selectedItems.length > 0 ? [] : [...items] });
81-
}
81+
};
8282

8383
renderItemRow = (item, index) => {
8484
const { selectType } = this.props;
@@ -121,7 +121,7 @@ class MockTableGridExample extends React.Component {
121121
</TableGrid.Col>
122122
</TableGrid.Row>
123123
);
124-
}
124+
};
125125

126126
render() {
127127
const { items, selectedItems, sortField, isAscending } = this.state;

packages/patternfly-3/patternfly-react-extensions/src/components/TableGrid/_mocks_/mockVirtualTableGridExample.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ class MockVirtualTableGridExample extends React.Component {
5656
});
5757

5858
this.setState({ items, sortField: id, isAscending: updateAscending });
59-
}
59+
};
6060

6161
onSelect = (item, field) => {
6262
this.setState({ selectedItem: item, selectedField: field });
63-
}
63+
};
6464

6565
toggleSelection = item => {
6666
const { selectedItems } = this.state;
@@ -73,12 +73,12 @@ class MockVirtualTableGridExample extends React.Component {
7373
newSelections = [...selectedItems, item];
7474
}
7575
this.setState({ selectedItems: newSelections });
76-
}
76+
};
7777

7878
toggleAllSelections = () => {
7979
const { items, selectedItems } = this.state;
8080
this.setState({ selectedItems: selectedItems.length > 0 ? [] : [...items] });
81-
}
81+
};
8282

8383
ItemHeader = tableData => {
8484
const { numItems, selectType, selectedItems, sortField, isAscending } = tableData;
@@ -134,7 +134,7 @@ class MockVirtualTableGridExample extends React.Component {
134134
</VirtualTableGrid.ColumnHeader>
135135
</VirtualTableGrid.Head>
136136
);
137-
}
137+
};
138138

139139
ItemRow = rowProps => {
140140
const { obj, tableData, index } = rowProps;
@@ -177,7 +177,7 @@ class MockVirtualTableGridExample extends React.Component {
177177
</VirtualTableGrid.Col>
178178
</VirtualTableGrid.Row>
179179
);
180-
}
180+
};
181181

182182
render() {
183183
const { items, selectedItem, selectedItems, selectedField, sortField, isAscending } = this.state;

packages/patternfly-3/patternfly-react-extensions/src/components/VerticalTabs/_mocks_/mockVerticalTabsExample.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class MockVerticalTabsExample extends React.Component {
99

1010
onActivateTab = id => {
1111
this.setState({ activeTabId: id });
12-
}
12+
};
1313

1414
render() {
1515
const { restrictTabs, wrapStyle } = this.props;

packages/patternfly-3/patternfly-react-wooden-tree/src/components/TreeView/TreeViewExample.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class TreeViewExample extends React.Component {
6969
}
7070
}
7171
this.setState({ tree });
72-
}
72+
};
7373

7474
render() {
7575
return (

packages/patternfly-3/patternfly-react/src/common/Timer.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ class Timer {
1111
// startTimer optionally takes a new func and delay so the timer instance can be reused.
1212
startTimer(func, delay = -1) {
1313
this.clearTimer();
14-
if (func) { this.execute = func; }
15-
if (delay >= 0) { this.delay = delay; }
14+
if (func) {
15+
this.execute = func;
16+
}
17+
if (delay >= 0) {
18+
this.delay = delay;
19+
}
1620
this.timer = setTimeout(this.execute, this.delay);
1721
}
1822
clearTimer() {

packages/patternfly-3/patternfly-react/src/common/closestPolyfill.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export function closest(selector) {
99
let el = this;
1010
if (document.documentElement.contains(el)) {
1111
while (el && el.nodeType === 1) {
12-
if (el.matches(selector)) { return el; }
12+
if (el.matches(selector)) {
13+
return el;
14+
}
1315
el = el.parentElement || el.parentNode;
1416
}
1517
}

0 commit comments

Comments
 (0)