Skip to content

Commit

Permalink
fix(prettier): change printWidth to 120 and expose rule in eslint-plu…
Browse files Browse the repository at this point in the history
…gin (patternfly#524)

* fix(prettier): change printWidth to 120 and expose rule in eslint-plugin

affects: eslint-plugin-patternfly-react, patternfly-react

ISSUES CLOSED: 439

* add all patternfly next rules

* format login components
  • Loading branch information
priley86 authored and dgutride committed Aug 13, 2018
1 parent 111bebd commit a68ac11
Show file tree
Hide file tree
Showing 409 changed files with 1,385 additions and 5,139 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
package.json
packages/**/dist/**/*.js
packages/**/.cache/**/*.js
scripts/generators/**/templates/**/*.js
6 changes: 5 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "none"
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false,
"printWidth": 120
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"node-sass": "^4.8.3",
"npmlog": "^4.1.2",
"plop": "^2.0.0",
"prettier": "^1.11.1",
"prettier": "^1.14.2",
"prettier-eslint": "^8.8.1",
"prop-types": "^15.6.1",
"raf": "^3.4.0",
Expand Down Expand Up @@ -124,7 +124,7 @@
"lint:js": "eslint --max-warnings 0 packages storybook scripts",
"lint:styles": "yarn stylelint",
"precommit": "lint-staged",
"prettier": "prettier --write --single-quote --trailing-comma=none 'storybook/**/*.js' 'packages/**/src/**/*.js'",
"prettier": "prettier --write 'storybook/**/*.js' 'packages/**/*.js' 'scripts/**/*.js'",
"semantic-release": "lerna-semantic-release pre && lerna-semantic-release post && lerna-semantic-release perform",
"start": "concurrently \"yarn storybook:run\" \"yarn storybook:openurl\"",
"start:docs": "yarn build && lerna run develop --scope=@patternfly/react-docs --stream",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ module.exports = {
'no-prototype-builtins': 'off',
'no-restricted-syntax': 'off',
'no-underscore-dangle': 'off',
'no-unused-expressions': [
'error',
{ allowShortCircuit: true, allowTernary: true }
],
'no-unused-expressions': ['error', { allowShortCircuit: true, allowTernary: true }],
'no-unused-vars': [
'error',
{
Expand All @@ -40,7 +37,10 @@ module.exports = {
}
],
'no-use-before-define': 'off',
'prettier/prettier': 'error',
'prettier/prettier': [
'error',
{ semi: true, singleQuote: true, tabWidth: 2, trailingComma: 'none', useTabs: false, printWidth: 120 }
],
'react/no-array-index-key': 'off',
'react/forbid-prop-types': 'off',
'react/jsx-filename-extension': 'off',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ module.exports = {
const [importMap = {}] = context.options;
return {
ImportDeclaration(node) {
const defaultImport = node.specifiers.find(
spec => spec.type === 'ImportDefaultSpecifier'
);
const defaultImport = node.specifiers.find(spec => spec.type === 'ImportDefaultSpecifier');
if (!defaultImport) {
return;
}
Expand All @@ -29,18 +27,15 @@ module.exports = {
if (expectedName && expectedName !== receivedName) {
context.report({
node,
message:
'Expected default import to be named "{{ expected }}" but received "{{ received }}"',
message: 'Expected default import to be named "{{ expected }}" but received "{{ received }}"',
data: {
expected: expectedName,
received: receivedName
},
fix(fixer) {
const [varDecl] = context.getDeclaredVariables(node);
return [
...varDecl.references.map(ref =>
fixer.replaceText(ref.identifier, expectedName)
),
...varDecl.references.map(ref => fixer.replaceText(ref.identifier, expectedName)),
fixer.replaceText(defaultImport, expectedName)
];
}
Expand Down
4 changes: 1 addition & 3 deletions packages/patternfly-react/src/common/closestPolyfill.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export const matches =
Element.prototype.matches ||
Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector;
Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;

if (!Element.prototype.matches) {
Element.prototype.matches = matches;
Expand Down
30 changes: 6 additions & 24 deletions packages/patternfly-react/src/common/controlled.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,12 @@ const controlled = ({ types, defaults = {}, persist }) => WrappedComponent => {

componentDidMount() {
this.loadPersistent();
window &&
window.addEventListener &&
window.addEventListener('beforeunload', this.savePersistent);
window && window.addEventListener && window.addEventListener('beforeunload', this.savePersistent);
}

componentWillUnmount() {
this.savePersistent();
window &&
window.removeEventListener &&
window.removeEventListener('beforeunload', this.savePersistent);
window && window.removeEventListener && window.removeEventListener('beforeunload', this.savePersistent);
}

setControlledState = updater => {
Expand All @@ -57,37 +53,23 @@ const controlled = ({ types, defaults = {}, persist }) => WrappedComponent => {

loadPersistent = () => {
if (persist && persist.length > 0) {
const fromPersisted =
window &&
window.sessionStorage &&
window.sessionStorage.getItem(this.sessionKey());
const fromPersisted = window && window.sessionStorage && window.sessionStorage.getItem(this.sessionKey());
fromPersisted && this.setState(JSON.parse(fromPersisted));
}
};

savePersistent = () => {
if (persist && persist.length > 0) {
const toPersist = selectKeys(this.state, persist);
window &&
window.sessionStorage &&
window.sessionStorage.setItem(
this.sessionKey(),
JSON.stringify(toPersist)
);
window && window.sessionStorage && window.sessionStorage.setItem(this.sessionKey(), JSON.stringify(toPersist));
}
};

sessionKey = () => this.props.sessionKey || JSON.stringify(persist);

render() {
const controlledStateProps = filterKeys(
this.props,
key => types.hasOwnProperty(key) && this.props[key] !== null
);
const otherProps = filterKeys(
this.props,
key => !types.hasOwnProperty(key)
);
const controlledStateProps = filterKeys(this.props, key => types.hasOwnProperty(key) && this.props[key] !== null);
const otherProps = filterKeys(this.props, key => !types.hasOwnProperty(key));
return (
<WrappedComponent
setControlledState={this.setControlledState}
Expand Down
13 changes: 4 additions & 9 deletions packages/patternfly-react/src/common/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export const debounce = (func, wait) => {
};

/** Returns true if propName is a non-null, defined property of the props object (can be any object, not just React props). */
export const propExists = (props, propName) =>
props && props.hasOwnProperty(propName) && props[propName] != null;
export const propExists = (props, propName) => props && props.hasOwnProperty(propName) && props[propName] != null;

/** Given two objects (props and state), returns the value of propName from props if present, or from state otherwise. */
export const propOrState = (props, state, propName) =>
Expand All @@ -36,18 +35,14 @@ export const selectKeys = (obj, keys, fn = val => val) =>
keys.reduce((values, key) => ({ ...values, [key]: fn(obj[key]) }), {});

/** Returns a subset of the given object with a validator function applied to its keys. */
export const filterKeys = (obj, validator) =>
selectKeys(obj, Object.keys(obj).filter(validator));
export const filterKeys = (obj, validator) => selectKeys(obj, Object.keys(obj).filter(validator));

/** Returns a subset of the given object with the given keys left out. */
export const excludeKeys = (obj, keys) =>
filterKeys(obj, key => !keys.includes(key));
export const excludeKeys = (obj, keys) => filterKeys(obj, key => !keys.includes(key));

/** Returns the given React children prop as a regular array of React nodes. */
export const childrenToArray = children =>
children &&
React.Children.count(children) > 0 &&
React.Children.toArray(children);
children && React.Children.count(children) > 0 && React.Children.toArray(children);

/** Filters the given React children prop with the given validator function. Returns an array of nodes. */
export const filterChildren = (children, validator) => {
Expand Down
5 changes: 1 addition & 4 deletions packages/patternfly-react/src/common/patternfly.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ const mockLayout = {
removeChangeListener: () => {}
};

const layout =
process.env.NODE_ENV === 'test'
? mockLayout
: Break({ mobile: 0, ...patternfly.pfBreakpoints });
const layout = process.env.NODE_ENV === 'test' ? mockLayout : Break({ mobile: 0, ...patternfly.pfBreakpoints });

export { patternfly, c3ChartDefaults, layout };
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ const AboutModal = ({
closeText,
...props
}) => (
<Modal
className={className}
contentClassName="about-modal-pf"
show={show}
onHide={onHide}
{...props}
>
<Modal className={className} contentClassName="about-modal-pf" show={show} onHide={onHide} {...props}>
<Modal.Header>
<Modal.CloseButton onClick={onHide} closeText={closeText} />
</Modal.Header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,17 @@ import { withInfo } from '@storybook/addon-info';
import { defaultTemplate } from 'storybook/decorators/storyTemplates';
import { name } from '../../../package.json';

import {
storybookPackageName,
STORYBOOK_CATEGORY
} from 'storybook/constants/siteConstants';
import {
AboutModal,
AboutModalVersions,
AboutModalVersionItem
} from '../../index';
import { storybookPackageName, STORYBOOK_CATEGORY } from 'storybook/constants/siteConstants';
import { AboutModal, AboutModalVersions, AboutModalVersionItem } from '../../index';

import {
MockAboutModal,
MockAboutModalSource
} from './__mocks__/mockAboutModal';
import { MockAboutModal, MockAboutModalSource } from './__mocks__/mockAboutModal';

const stories = storiesOf(
`${storybookPackageName(name)}/${
STORYBOOK_CATEGORY.COMMUNICATION
}/About Modal`,
module
);
const stories = storiesOf(`${storybookPackageName(name)}/${STORYBOOK_CATEGORY.COMMUNICATION}/About Modal`, module);

stories.addDecorator(
defaultTemplate({
title: 'About Modal',
documentationLink:
'http://www.patternfly.org/pattern-library/communication/about-modal/'
documentationLink: 'http://www.patternfly.org/pattern-library/communication/about-modal/'
})
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React from 'react';
import { mount } from 'enzyme';
import {
AboutModal,
AboutModalVersions,
AboutModalVersionItem
} from '../../index';
import { AboutModal, AboutModalVersions, AboutModalVersionItem } from '../../index';

const testAboutModal = props => (
<AboutModal
Expand Down
6 changes: 1 addition & 5 deletions packages/patternfly-react/src/components/Alert/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import PropTypes from 'prop-types';
import { Button } from '../Button';
import { Icon } from '../Icon';
import { getClassName, getIconName, warnIfDeprecatedType } from './helpers';
import {
ALERT_TYPES,
DEPRECATED_ALERT_TYPES,
ALERT_TYPE_ERROR
} from './AlertConstants';
import { ALERT_TYPES, DEPRECATED_ALERT_TYPES, ALERT_TYPE_ERROR } from './AlertConstants';

/**
* Alert Component for Patternfly React
Expand Down
26 changes: 7 additions & 19 deletions packages/patternfly-react/src/components/Alert/Alert.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,17 @@ import { action } from '@storybook/addon-actions';
import { withKnobs, text, select } from '@storybook/addon-knobs';
import { withInfo } from '@storybook/addon-info';
import { defaultTemplate } from 'storybook/decorators/storyTemplates';
import {
storybookPackageName,
DOCUMENTATION_URL,
STORYBOOK_CATEGORY
} from 'storybook/constants/siteConstants';
import { storybookPackageName, DOCUMENTATION_URL, STORYBOOK_CATEGORY } from 'storybook/constants/siteConstants';
import { ALERT_TYPES } from './AlertConstants';
import { Alert } from './index';
import { name } from '../../../package.json';

const stories = storiesOf(
`${storybookPackageName(name)}/${STORYBOOK_CATEGORY.WIDGETS}/Alert`,
module
);
const stories = storiesOf(`${storybookPackageName(name)}/${STORYBOOK_CATEGORY.WIDGETS}/Alert`, module);
stories.addDecorator(withKnobs);
stories.addDecorator(
defaultTemplate({
title: 'Alert / Inline Notification',
documentationLink: `${
DOCUMENTATION_URL.PATTERNFLY_ORG_COMMUNICATION
}inline-notifications/`
documentationLink: `${DOCUMENTATION_URL.PATTERNFLY_ORG_COMMUNICATION}inline-notifications/`
})
);

Expand All @@ -32,7 +23,9 @@ stories.add(
withInfo('Those are the available alert types')(() =>
ALERT_TYPES.map((type, index) => (
<Alert key={index} type={type} onDismiss={action(`${type}Dismissed`)}>
I am an Alert with type=&quot;{type}&quot;
I am an Alert with type=&quot;
{type}
&quot;
</Alert>
))
)
Expand All @@ -42,12 +35,7 @@ stories.add(
'Alert without dismiss',
withInfo(`This is the Alert without a dismiss icon.`)(() => (
<Alert type={select('Type', ALERT_TYPES)}>
<span>
{text(
'Label',
'Well done! You successfully read this important alert message.'
)}
</span>
<span>{text('Label', 'Well done! You successfully read this important alert message.')}</span>
</Alert>
))
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ export const ALERT_TYPE_SUCCESS = 'success';
export const ALERT_TYPE_INFO = 'info';
export const ALERT_TYPE_DANGER = 'danger'; // deprecated!!!

export const ALERT_TYPES = [
ALERT_TYPE_ERROR,
ALERT_TYPE_WARNING,
ALERT_TYPE_SUCCESS,
ALERT_TYPE_INFO
];
export const ALERT_TYPES = [ALERT_TYPE_ERROR, ALERT_TYPE_WARNING, ALERT_TYPE_SUCCESS, ALERT_TYPE_INFO];

export const DEPRECATED_ALERT_TYPES = [ALERT_TYPE_DANGER];
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import { storiesOf } from '@storybook/react';
import { withKnobs } from '@storybook/addon-knobs';
import {
storybookPackageName,
STORYBOOK_CATEGORY
} from 'storybook/constants/siteConstants';
import {
NavApplicationLauncherStory,
WrapperNavApplicationLauncherStory
} from './Stories/index';
import { storybookPackageName, STORYBOOK_CATEGORY } from 'storybook/constants/siteConstants';
import { NavApplicationLauncherStory, WrapperNavApplicationLauncherStory } from './Stories/index';
import { name } from '../../../package.json';

const stories = storiesOf(
`${storybookPackageName(name)}/${
STORYBOOK_CATEGORY.APPLICATION_FRAMEWORK
}/Launcher`,
module
);
const stories = storiesOf(`${storybookPackageName(name)}/${STORYBOOK_CATEGORY.APPLICATION_FRAMEWORK}/Launcher`, module);
stories.addDecorator(withKnobs);

NavApplicationLauncherStory(stories);
Expand Down
Loading

0 comments on commit a68ac11

Please sign in to comment.