Skip to content

Commit

Permalink
Add tslint-plugin-prettier and apply code formatting (#2810)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mturley authored and redallen committed Oct 2, 2019
1 parent af0c7aa commit 0d072ea
Show file tree
Hide file tree
Showing 648 changed files with 6,367 additions and 5,262 deletions.
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package.json
packages/**/dist/**/*.js
packages/**/.cache/**/*.js
scripts/generators/**/templates/**/*.js
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false,
"printWidth": 120
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"minimist": "^1.2.0",
"mutation-observer": "^1.0.3",
"plop": "^2.0.0",
"prettier": "^1.18.2",
"react": "^16.4.0",
"react-dom": "^16.4.0",
"sass-loader": "^6.0.6",
Expand All @@ -71,6 +72,8 @@
"stylelint-config-standard": "^18.2.0",
"ts-jest": "24.1.0",
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"tslint-react": "^3.6.0"
},
"scripts": {
Expand All @@ -88,6 +91,7 @@
"lint:style": "stylelint \"**/sass/**/*.scss\" \"!**/dist/**/*.scss\"",
"lint:ts": "node --max-old-space-size=4096 node_modules/.bin/tslint --project ./tslint.config.json --config tslint.json",
"lint:versions": "node ./packages/patternfly-4/verifyCoreVersions.js",
"prettier": "node node_modules/.bin/prettier --write \"storybook/**/*.{js,ts,tsx}\" \"packages/**/*.{js,ts,tsx}\" \"scripts/**/*.{js,ts,tsx}\"",
"start": "yarn start:pf3",
"start:cypress": "lerna run cypress:open",
"start:demo-app": "lerna run start:demo-app --stream",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class CatalogTile extends React.Component {
}

this.descFullHeight = ref.clientHeight;
}
};

handleDescriptionSpanRef = ref => {
if (!ref) {
return;
}

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

handleClick = e => {
const { onClick, href } = this.props;
Expand All @@ -61,7 +61,7 @@ class CatalogTile extends React.Component {
if (onClick) {
onClick(e);
}
}
};

renderBadges = badges => {
if (!badges || !badges.length) {
Expand All @@ -75,7 +75,7 @@ class CatalogTile extends React.Component {
))}
</div>
);
}
};

render() {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ class CatalogTileViewCategory extends React.Component {
const rightSpacerWidth = this.categoryContainer.clientWidth % 235;
this.setState({ numShown, rightSpacerWidth });
}
}
};

handleRef = ref => {
if (!ref) {
return;
}
this.categoryContainer = ref;
}
};

render() {
const { children, className, title, totalItems, viewAllText, viewAll, onViewAll, ...props } = this.props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MockCatalogTileViewExample extends React.Component {

onViewAll = id => {
this.setState({ showAll: id });
}
};

getBadges = item => {
const badges = [];
Expand All @@ -39,13 +39,13 @@ class MockCatalogTileViewExample extends React.Component {
}

return badges;
}
};

renderEmptyState = category => (
<EmptyState className="blank-slate-content-pf">
<EmptyState.Info>There are no items in this category.</EmptyState.Info>
</EmptyState>
)
);

renderCategory = category => {
const { showAll } = this.state;
Expand Down Expand Up @@ -80,7 +80,7 @@ class MockCatalogTileViewExample extends React.Component {
}

return null;
}
};

render() {
const { showAll } = this.state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const DiffView = ({
const files = parseDiff(gitDiff);
const hunk = files[0].hunks;

if (hunk.length === 0) { return emptyState; }
if (hunk.length === 0) {
return emptyState;
}
return hunk && <Diff className={classes} hunks={hunk} markEdits={markEdits} viewType={viewType} {...props} />;
}

Expand All @@ -53,7 +55,9 @@ const DiffView = ({
/>
);

if (patch === '') { return emptyState; }
if (patch === '') {
return emptyState;
}
return <div>{files.map(renderFile)}</div>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ class MockFilterSidePanelExample extends React.Component {
const showAllCategories = { ...this.state.showAllCategories };
showAllCategories[id] = !showAllCategories[id];
this.setState({ showAllCategories });
}
};

onFilterChange = (id, value) => {
const activeFilters = { ...this.state.activeFilters };
activeFilters[id] = value;
this.setState({ activeFilters });
}
};

getStars = count => {
const stars = [];
Expand All @@ -73,7 +73,7 @@ class MockFilterSidePanelExample extends React.Component {
{stars}
</span>
);
}
};

render() {
const { activeFilters, showAllCategories } = this.state;
Expand Down Expand Up @@ -259,7 +259,7 @@ class MockFilterSidePanelExample extends React.Component {
checked={activeFilters.paymentDinersClub}
onChange={e => this.onFilterChange('paymentDinersClub', e.target.checked)}
>
{'Diner\'s Club'}
{"Diner's Club"}
</FilterSidePanel.CategoryItem>
</FilterSidePanel.Category>
<FilterSidePanel.Category
Expand Down Expand Up @@ -301,7 +301,9 @@ class MockFilterSidePanelExample extends React.Component {
count={8}
checked={activeFilters.mileage10}
onChange={e => this.onFilterChange('mileage10', e.target.checked)}
>{'< 20'}</FilterSidePanel.CategoryItem>
>
{'< 20'}
</FilterSidePanel.CategoryItem>
</FilterSidePanel.Category>
<FilterSidePanel.Category
title="Rating"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const createItemProps = (item, selectedItem, className, onItemClick) => {
active: selectedItem.id === item.id
};

if (item.disabled) { return { ...itemProps, disabled: true }; }
if (item.disabled) {
return { ...itemProps, disabled: true };
}
return { ...itemProps, onClick: e => onItemClick({ e, id: item.id, name: item.name }) };
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class SelectInput extends React.Component {
}

componentDidMount() {
if (this.props.focus) { this.searchInput.current.focus(); }
if (this.props.focus) {
this.searchInput.current.focus();
}
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ class StatefulWrapperSelect extends Component {
const { options } = this.state;
const results = [];
options.forEach(opt => {
if (opt.name.includes(search)) { results.push(opt); }
if (opt.name.includes(search)) {
results.push(opt);
}
});
return results;
}
};

onSearch = e => {
e.persist();
Expand All @@ -43,17 +45,21 @@ class StatefulWrapperSelect extends Component {
}, 700);
}
);
} else { this.setState({ isSearching: false, searchValue: '' }); }
}
} else {
this.setState({ isSearching: false, searchValue: '' });
}
};

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

onItemClick = host =>
this.setState({ selected: { id: host.id, name: host.name }, open: false, isSearching: false, searchValue: '' })
this.setState({ selected: { id: host.id, name: host.name }, open: false, isSearching: false, searchValue: '' });

handleClickOutside = () => {
if (this.state.open === true) { this.onToggle(); }
}
if (this.state.open === true) {
this.onToggle();
}
};

render() {
const { open, isSearching, searchValue, selected, isLoading, options, matched } = this.state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class MockTableGridExample extends React.Component {
});

this.setState({ items, sortField: id, isAscending: updateAscending });
}
};

onSelect = (item, field) => {
this.setState({ selectedItem: item, selectedField: field });
}
};

toggleSelection = item => {
const { selectedItems } = this.state;
Expand All @@ -73,12 +73,12 @@ class MockTableGridExample extends React.Component {
newSelections = [...selectedItems, item];
}
this.setState({ selectedItems: newSelections });
}
};

toggleAllSelections = () => {
const { items, selectedItems } = this.state;
this.setState({ selectedItems: selectedItems.length > 0 ? [] : [...items] });
}
};

renderItemRow = (item, index) => {
const { selectType } = this.props;
Expand Down Expand Up @@ -121,7 +121,7 @@ class MockTableGridExample extends React.Component {
</TableGrid.Col>
</TableGrid.Row>
);
}
};

render() {
const { items, selectedItems, sortField, isAscending } = this.state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class MockVirtualTableGridExample extends React.Component {
});

this.setState({ items, sortField: id, isAscending: updateAscending });
}
};

onSelect = (item, field) => {
this.setState({ selectedItem: item, selectedField: field });
}
};

toggleSelection = item => {
const { selectedItems } = this.state;
Expand All @@ -73,12 +73,12 @@ class MockVirtualTableGridExample extends React.Component {
newSelections = [...selectedItems, item];
}
this.setState({ selectedItems: newSelections });
}
};

toggleAllSelections = () => {
const { items, selectedItems } = this.state;
this.setState({ selectedItems: selectedItems.length > 0 ? [] : [...items] });
}
};

ItemHeader = tableData => {
const { numItems, selectType, selectedItems, sortField, isAscending } = tableData;
Expand Down Expand Up @@ -134,7 +134,7 @@ class MockVirtualTableGridExample extends React.Component {
</VirtualTableGrid.ColumnHeader>
</VirtualTableGrid.Head>
);
}
};

ItemRow = rowProps => {
const { obj, tableData, index } = rowProps;
Expand Down Expand Up @@ -177,7 +177,7 @@ class MockVirtualTableGridExample extends React.Component {
</VirtualTableGrid.Col>
</VirtualTableGrid.Row>
);
}
};

render() {
const { items, selectedItem, selectedItems, selectedField, sortField, isAscending } = this.state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MockVerticalTabsExample extends React.Component {

onActivateTab = id => {
this.setState({ activeTabId: id });
}
};

render() {
const { restrictTabs, wrapStyle } = this.props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class TreeViewExample extends React.Component {
}
}
this.setState({ tree });
}
};

render() {
return (
Expand Down
8 changes: 6 additions & 2 deletions packages/patternfly-3/patternfly-react/src/common/Timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ class Timer {
// startTimer optionally takes a new func and delay so the timer instance can be reused.
startTimer(func, delay = -1) {
this.clearTimer();
if (func) { this.execute = func; }
if (delay >= 0) { this.delay = delay; }
if (func) {
this.execute = func;
}
if (delay >= 0) {
this.delay = delay;
}
this.timer = setTimeout(this.execute, this.delay);
}
clearTimer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export function closest(selector) {
let el = this;
if (document.documentElement.contains(el)) {
while (el && el.nodeType === 1) {
if (el.matches(selector)) { return el; }
if (el.matches(selector)) {
return el;
}
el = el.parentElement || el.parentNode;
}
}
Expand Down
Loading

0 comments on commit 0d072ea

Please sign in to comment.