Skip to content

Feature/eslint config#77

Open
gavinorland wants to merge 8 commits intomasterfrom
feature/eslint-config
Open

Feature/eslint config#77
gavinorland wants to merge 8 commits intomasterfrom
feature/eslint-config

Conversation

@gavinorland
Copy link
Collaborator

Hey guys, so here I have removed numerous ESLint exemptions, and brought all code into alignment accordingly. I have also changed the glob pattern for ESLint in the package.json, as /**/ was not detecting files in the root of each package!

If you have any views on the remaining overrides please let me know. If approved, perhaps we can copy this for govuk-react. Later also perhaps think about further steps such as running it on commit (although I know people have had issues with this) and possibly introducing Prettier. This addresses #5.

@codecov
Copy link

codecov bot commented Aug 17, 2018

Codecov Report

Merging #77 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #77   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          22     22           
  Lines         185    185           
  Branches       42     43    +1     
=====================================
  Hits          185    185
Impacted Files Coverage Δ
components/countdown-text-area/src/index.js 100% <ø> (ø) ⬆️
components/arrow-left/src/index.js 100% <ø> (ø) ⬆️
components/result-count/src/index.js 100% <ø> (ø) ⬆️
components/remove-button/src/index.js 100% <ø> (ø) ⬆️
components/keyline/src/index.js 100% <ø> (ø) ⬆️
components/count/src/index.js 100% <ø> (ø) ⬆️
components/open-button/src/index.js 100% <100%> (ø) ⬆️
components/counter-bar/src/index.js 100% <100%> (ø) ⬆️
components/result-count-title/src/index.js 100% <100%> (ø) ⬆️
components/table-of-contents/src/Section/index.js 100% <100%> (ø) ⬆️
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8bd5693...15a7afa. Read the comment docs.

@gavinorland gavinorland requested a review from 7oque August 20, 2018 08:22
const defaultTransform = value => (value || '-');

return <ArrayObjectTable
return (<ArrayObjectTable
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the parens here really needed?

i get the need for a bracket when there's nothing else on the line, but as this line also has the start of a JSX tag surely that's OK?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On current config react/jsx-wrap-multilines objects without these - I'll take a look at options...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok cool - i think i'm not a fan of that rule then 😁

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK... There is no option enforcing that JSX is never wrapped in parens but I could turn off the rule requiring that multiline JSX is wrapped.

Wrapping is not necessary for multi-line JSX, but is advised by FB and Airbnb, FB saying it "avoids the pitfalls of automatic semicolon insertion". Shall we say that we will turn off the rule, though? This will mean there can be parens around both single and multiline JSX, but it is not required or "fixed" to be so. And our policy could be not to do it at all. That's fine with me.

btw If there is a return statement then a line break before the JSX, then yes, a bracket is needed or the return is deemed illegal, but I guess we could generally avoid this too and always begin with our JSX or opening element.

const fields = [
{ key: 'one', heading: 'One' },
{ key: 'two', heading: 'Two', transform: value => value ? value.toLowerCase() : '' },
{ key: 'two', heading: 'Two', transform: value => (value ? value.toLowerCase() : '') },
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure i see the value in the brackets here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is "Arrow function used ambiguously with a conditional expression" (no-confusing-arrow). Again will take a look at options...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah - as i said this one i'm not sure about - there's potentially value in that rule i guess, especially if the code in the ternary gets more complex and spread over multiple lines

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. yes, there isn't any multi-line setting. We could override this rule if you like (turn it off)?

Copy link
Owner

@stevesims stevesims left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some things to change

i didn't reach the end of this whilst reviewing - many of my comments have knock-on implications and would likely get repeated a lot as i continued through this PR

@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't see the need to have a line break here - react-emotion is a module that's needed for this component to work, and it's effectively the same type of fundamental module as react and prop-types to me

stories.addDecorator(withKnobs);

stories.add('Component default', () => <CompactTableAccordionGroup title="Title" expanded="expanded">
stories.add('Component default', () => (<CompactTableAccordionGroup title="Title" expanded="expanded">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once again, not sure why there's a bracket here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that one's been given a bracket because it's multiline JSX. I'm going to override that rule now though.

</CompactTableAccordionGroup>));

examples.add('No children', () => <CompactTableAccordionGroup open title="Title" expanded="expanded"/>);
examples.add('No children', () => <CompactTableAccordionGroup open title="Title" expanded="expanded" />);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and given the propensity for brackets elsewhere, why does this not have one?

indeed for me as I'm cool with this line not bracketing the return value, this example makes the case that the others also shouldn't need brackets

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not given a bracket by ESLint because it's only on a single line. :)

expect(wrapper
.find('Title')
.childAt(0)
.text()).toBe('Title');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... than this, as here it's jolly easy to miss the closing ) after .text()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is due to function-paren-newline. Will look at options on this one too..

const changeHandler = jest.fn();
const wrapper = mount(
<CompactTableAccordionGroup expanded="Expanded" onChange={changeHandler}>
const wrapper = mount(<CompactTableAccordionGroup expanded="Expanded" onChange={changeHandler}>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd have left these myself - having the <CompactTableAccordionGroup start on a fresh line makes it a bit easier to read what the mount call is rendering when skimming the code

* <CounterBar.Total
* score={15}
* scoreColor="yellow"
* scoreBackgroundColor="pink">All counters</CounterBar.Total>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're going to split the CounterBar.Total opening tag across multiple lines, then IMHO it's best to put the content and closing tags in separate lines to make the code more reasonable

plus also the indent should be kept consistent, i.e. attributes should go 2 characters in

i.e. this should be:

  *   <CounterBar.Total
  *     score={15}
  *     scoreColor="yellow"
  *     scoreBackgroundColor="pink"
  *   >
  *     All counters
  *   </CounterBar.Total>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This one isn't an ESLint auto-fix!

* <CounterBar.Counter
* score={2}
* scoreColor="orange"
* scoreBackgroundColor="blue">Counter 2</CounterBar.Counter>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar formatting comments apply here

and indeed through the rest of these examples

</CounterBar.Counters>
</CounterBar>),
);
</CounterBar>));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm really not keen on having the closing bracket here for the stories.add call at a different indent level - it really grates for me when i'm reading this code, and some editors may try to maintain the 4 spaces when writing the next line of code

i.e. the closing bracket should go onto the next line, as it was before

indeed the old code here was fine, except it should not have had the trailing ,

this comment applies to the rest of this file too

This commits removes most of the core overrides, meaning Airbnb's rules apply once again.
This makes all the files respect the new ESLint rules. It's mostly adjusting line lengths (100 limit) and removing whitespace. I have also tried to make blank lines between import blocks uniform.
There was a surplus `/**/` in here, preventing these scripts from finding the files.
There seems to be a problem with the "zero or more folders" glob so it was missing out root files. Have got around that - we can consider regex in the future. Files here are corrected accordingly.
This branch has also been rebased onto the latest master, meaning this should be done before further edits are made.
@gavinorland gavinorland force-pushed the feature/eslint-config branch from 6634f93 to 3423bc7 Compare September 3, 2018 13:26
`function-paren-newline` and `no-confusing-arrow` both get disabled here, we meaning don't need parens around JSX or around the ternaries in arrow functions. Also, `comma-dangle` is added with a special option which enables us to have our JSX blocks always properly aligned with no trailing comma and a closing paren on a separate line.

Changes to code are:

* Brackets removed in numerous places around JSX blocks where not required
* When JSX lines are very long or when components are mounted with children they generally begin on their own new line
* No trailing commas after JSX and closing parens on next line
* Fixes to tabbing of children
* `max-len` seems not to be taken into account by ESLint, but I have moved children onto a new line when line length would exceed 100 chars and generally kept to this rule elsewhere too
* No blank line between packages which are core ones, but kept one between core ones and our ones, and between our ones and Storybook ones
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants