From aebf1316a8fb564037cb8c20ff8476771a0d328d Mon Sep 17 00:00:00 2001 From: Hypnosphi <Filipp.Riabchun@jetbrains.com> Date: Wed, 6 Jun 2018 01:07:46 +0200 Subject: [PATCH] Fix eslint warnings --- addons/events/src/components/Event.js | 24 ++++++------- addons/jest/src/components/Panel.js | 4 +-- addons/storysource/src/StoryPanel.js | 34 ++++++++----------- .../viewport/src/manager/components/Panel.js | 10 +++--- dependencies.yml | 2 +- 5 files changed, 35 insertions(+), 39 deletions(-) diff --git a/addons/events/src/components/Event.js b/addons/events/src/components/Event.js index f47100af5082..b81d178ee6a0 100644 --- a/addons/events/src/components/Event.js +++ b/addons/events/src/components/Event.js @@ -76,6 +76,14 @@ const Wrapper = styled('div')({ width: '100%', }); +function getJSONFromString(str) { + try { + return JSON.parse(str); + } catch (e) { + return str; + } +} + class Item extends Component { static propTypes = { name: PropTypes.string.isRequired, @@ -89,13 +97,9 @@ class Item extends Component { payload: {}, }; - static getJSONFromString(str) { - try { - return JSON.parse(str); - } catch (e) { - return str; - } - } + state = { + isTextAreaShowed: false, + }; static getDerivedStateFromProps = ({ payload }, { prevPayload }) => { if (payload !== prevPayload) { @@ -103,7 +107,7 @@ class Item extends Component { return { failed: false, - payload: Item.getJSONFromString(payloadString), + payload: getJSONFromString(payloadString), payloadString, prevPayload, }; @@ -111,10 +115,6 @@ class Item extends Component { return null; }; - state = { - isTextAreaShowed: false, - }; - onChange = ({ target: { value } }) => { const newState = { payloadString: value, diff --git a/addons/jest/src/components/Panel.js b/addons/jest/src/components/Panel.js index f856bc54ad97..23b3a20ee980 100644 --- a/addons/jest/src/components/Panel.js +++ b/addons/jest/src/components/Panel.js @@ -64,8 +64,8 @@ const SuiteTotals = styled(({ successNumber, failedNumber, result, className }) const SuiteProgress = styled(({ successNumber, result, className }) => ( <div className={className} role="progressbar"> - <span style={{ width: `${successNumber / result.assertionResults.length * 100}%` }}> - {`${successNumber / result.assertionResults.length * 100}%`} + <span style={{ width: `${(successNumber / result.assertionResults.length) * 100}%` }}> + {`${(successNumber / result.assertionResults.length) * 100}%`} </span> </div> ))(() => ({ diff --git a/addons/storysource/src/StoryPanel.js b/addons/storysource/src/StoryPanel.js index 97023d1e6109..3b56f65723ed 100644 --- a/addons/storysource/src/StoryPanel.js +++ b/addons/storysource/src/StoryPanel.js @@ -44,31 +44,27 @@ const styles = { }, }; -export default class StoryPanel extends Component { - static areLocationsEqual(a, b) { - return ( - a.startLoc.line === b.startLoc.line && - a.startLoc.col === b.startLoc.col && - a.endLoc.line === b.endLoc.line && - a.endLoc.col === b.endLoc.col - ); - } - - static getLocationKeys(locationsMap) { - return locationsMap - ? Array.from(Object.keys(locationsMap)).sort( - (key1, key2) => locationsMap[key1].startLoc.line - locationsMap[key2].startLoc.line - ) - : []; - } +const areLocationsEqual = (a, b) => + a.startLoc.line === b.startLoc.line && + a.startLoc.col === b.startLoc.col && + a.endLoc.line === b.endLoc.line && + a.endLoc.col === b.endLoc.col; + +const getLocationKeys = locationsMap => + locationsMap + ? Array.from(Object.keys(locationsMap)).sort( + (key1, key2) => locationsMap[key1].startLoc.line - locationsMap[key2].startLoc.line + ) + : []; +export default class StoryPanel extends Component { state = { source: '// Here will be dragons 🐉' }; componentDidMount() { const { channel } = this.props; channel.on(EVENT_ID, ({ source, currentLocation, locationsMap }) => { - const locationsKeys = StoryPanel.getLocationKeys(locationsMap); + const locationsKeys = getLocationKeys(locationsMap); this.setState({ source, @@ -116,7 +112,7 @@ export default class StoryPanel extends Component { const story = this.createPart(storyRows, stylesheet, useInlineStyles); const storyKey = `${first}-${last}`; - if (StoryPanel.areLocationsEqual(location, currentLocation)) { + if (areLocationsEqual(location, currentLocation)) { return ( <div key={storyKey} ref={this.setSelectedStoryRef} style={styles.selectedStory}> {story} diff --git a/addons/viewport/src/manager/components/Panel.js b/addons/viewport/src/manager/components/Panel.js index db6f272ebfca..7a3b7bf1cddf 100644 --- a/addons/viewport/src/manager/components/Panel.js +++ b/addons/viewport/src/manager/components/Panel.js @@ -35,16 +35,16 @@ const getViewports = viewports => const setStoryDefaultViewportWait = 100; export class Panel extends Component { - static propTypes = { - channel: PropTypes.shape({}).isRequired, - api: PropTypes.shape({}).isRequired, - }; - static defaultOptions = { viewports: INITIAL_VIEWPORTS, defaultViewport: DEFAULT_VIEWPORT, }; + static propTypes = { + channel: PropTypes.shape({}).isRequired, + api: PropTypes.shape({}).isRequired, + }; + constructor(props, context) { super(props, context); this.state = { diff --git a/dependencies.yml b/dependencies.yml index c660055243dc..b4feffeab89f 100644 --- a/dependencies.yml +++ b/dependencies.yml @@ -35,7 +35,7 @@ collectors: settings: batch_mode: true batch_bootstrap: true - bootstrap_command: yarn --ignore-scripts --ignore-engines --silent + bootstrap_command: yarn --ignore-scripts --ignore-engines --silent && yarn lint:ts . --fix && yarn lint:js . --fix github_labels: - dependencies:update github_assignees: