Open ianb opened 7 years ago
This doesn't feel very useful to worry about right now.
Having just worked on SS for the first time in awhile, i felt like line-length in or code base greatly decreased legibility. Might be work reconsidering this
This could be cool. Note that any changes will need to pass the mozilla eslint rules, since exported code goes into mozilla-central :+1:
@johngruen Did you want all of prettier's formatting, or just a more managed maximum line length?
ESLint does have a max-len
rule which may do a bit of what you want.
UPDATE: This may actually do what you want, but produce a pretty sizable diff:
$ npx prettier "{bin,docs,server,static,test,webextension}/**/*.{css,js,json,md,scss,yml}" "*.md" --write
$ npm run lint:js
And it looks like everything still passes ESLint.
opened #4916 to discuss just adding the eslint rule. @pdehaan did you see any particularly nice examples of the before/after diff with prettier applied?
@6a68 It's a pretty massive diff, but I didn't see anything too amazing that would cause me to find equivalent ESLint rules to improve readability.
I ended up playing briefly w/ prettier CLI flags to try and get the prettier formatting as close to the current formatting as possible, but noticed that there wasn't always consistent spacing around parens, or usage of optional parens on arrow functions, etc. So I think in the case of overall code consistency prettier would really help. But there were also a few places where prettier's formatting wasn't as nice. Maybe if there were really offensive reformatting I think you can tell prettier to ignore specific lines/blocks of code. 🤷♂️
Here was my "final" $ prettier command:
npx prettier "{bin,docs,server,static,test,webextension}/**/*.{css,js,json,md,scss,yml}" "*.md" --write --arrow-parens=avoid --trailing-comma=all --print-width=110 --bracket-spacing
We could also add a .prettierignore file (or possibly reuse .eslintignore) if there were also certain l10n paths that we wanted to ignore. No point in reformatting a bunch of JSON l10n blobs. Which is also why I didn't bother trying to format the root *.json files -- since I wanted to avoid touching package.json and more importantly, package-lock.json.
This may also be useful: https://www.npmjs.com/package/pretty-quick We could run prettier only against staged files using git hooks.
I like prettier in concept, as a JavaScript reformatter. I'd be curious what it does, and if we can apply it generally across the codebase.
If it seems at all hard we should not put much effort into this.