Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] Unify linting and autoformatting #2914

Merged
merged 19 commits into from
Aug 29, 2019
Merged

[tests] Unify linting and autoformatting #2914

merged 19 commits into from
Aug 29, 2019

Conversation

lucleray
Copy link
Member

@lucleray lucleray commented Aug 29, 2019

This PR adds:

  • prettier to autoformat
  • eslint on the root folder to unify it across the repository
  • lint-staged to improve our code incrementally (only files that are touched in the commit are linted/prettified)
  • husky to add a hook on pre-commit

There are still many lint errors across the code base (yarn run lint to list them). Because of that, only now-client and now-cli are currently part of the CI step, but please add others packages when they pass lint!

To add a package to the CI step, simply add a script to the package:

{
  "scripts": {
    "test-lint": "eslint . --ext .ts,.js --ignore-path ../../.eslintignore"
  }
}

Eventually, we'll have all packages linted and we can simply run eslint from the root package.

Remarks:

  • Feel free to tweak "rules" in .eslintrc.json if a rule is not appropriate or causing too much problems. Please tweak the rule only for the specific package and not for the whole monorepo (unless necessary). The goal is to unify linting so please don't add too many rules 😅
  • Some rules are a bit looser than previous configuration (I removed eslint-config-airbnb because it is bloated with confusing rules and i believe we are smart programmers 🤓)

Todo:

  • add prettier and eslint on root
  • remove eslint from now-cli
  • add git hooks
  • remove git hooks in now-cli
  • remove git hooks in now-client
  • add CI step

Fixes #2912

@lucleray lucleray marked this pull request as ready for review August 29, 2019 08:28
@codecov-io
Copy link

codecov-io commented Aug 29, 2019

Codecov Report

Merging #2914 into canary will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           canary    #2914      +/-   ##
==========================================
- Coverage   11.06%   11.04%   -0.02%     
==========================================
  Files         267      267              
  Lines       10133    10133              
  Branches     1264     1266       +2     
==========================================
- Hits         1121     1119       -2     
- Misses       8922     8924       +2     
  Partials       90       90
Impacted Files Coverage Δ
src/util/dev/router.ts 78.04% <0%> (-0.53%) ⬇️
src/util/dev/server.ts 61.05% <0%> (-0.34%) ⬇️
src/util/pkg.ts 0% <0%> (ø) ⬆️
src/commands/deploy/legacy.ts 0% <0%> (ø) ⬆️
src/util/input/list.js 0% <0%> (ø) ⬆️

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 8b9426e...1ac88c3. Read the comment docs.

Copy link
Contributor

@rdev rdev left a comment

Choose a reason for hiding this comment

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

@lucleray Running yarn lint in the root of the repo with this results in

✖ 1516 problems (1193 errors, 323 warnings)
  107 errors and 0 warnings potentially fixable with the `--fix` option.

🤔

@lucleray
Copy link
Member Author

@rdev Improved eslint configuration and fixed some errors:

✖ 90 problems (62 errors, 28 warnings)
  25 errors and 0 warnings potentially fixable with the `--fix` option.

@styfle styfle changed the title Unify linting and autoformatting [tests] Unify linting and autoformatting Aug 29, 2019
@lucleray lucleray requested a review from dav-is as a code owner August 29, 2019 14:48
Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

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

Amazing work!

@dav-is
Copy link
Contributor

dav-is commented Aug 29, 2019

Could we publish an eslint plugin that uses the prettier plugin and add instructions for a standard ZEIT linting setup?

};

// Static builders are special cased in `@now/static-build`
function getBuilders(): Map<string, Builder> {
return new Map<string, Builder>([
['next', { src, use: '@now/next', config }],
['next', { src, use: '@now/next', config }]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we continue using trailing commas?

Copy link
Member Author

Choose a reason for hiding this comment

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

There was no trailing comma in now-cli so I went for no trailing comma.

Copy link
Contributor

Choose a reason for hiding this comment

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

@lucleray Tbh I prefer trailing commas because of the cleaner diffs 🤔
But it's not a strong stance

Copy link
Contributor

Choose a reason for hiding this comment

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

I personally think trailing commas give cleaner diffs, what do you think @styfle

Copy link
Member

Choose a reason for hiding this comment

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

I agree. I like trailing commas because they're less noise when reviewing PRs.

In this case, however, let's try to keep now-cli consistent because that was the original repo and has all the history here.

Copy link
Member

Choose a reason for hiding this comment

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

Also because of prettier right?

Copy link
Contributor

Choose a reason for hiding this comment

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

prettier allows you to configure trailing commas

Copy link
Member

@TooTallNate TooTallNate left a comment

Choose a reason for hiding this comment

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

Is there any command that we need to run to get the pre-commit hook working properly?

@TooTallNate
Copy link
Member

@lucleray What do you think about unifying the .editorconfig as well?

@kodiakhq kodiakhq bot merged commit 236f5f4 into canary Aug 29, 2019
@kodiakhq kodiakhq bot deleted the better-lint branch August 29, 2019 19:17
AndyBitz pushed a commit that referenced this pull request Sep 4, 2019
* add prettier and eslint on root

* remove eslint from now-cli

* adjust root package.json

* adjust eslintignore

* adjust now-cli rules

* remove @zeit/git-hooks in packages

* adjust now-client eslint config

* add lint-staged and hook on pre-commit

* add pre-commit script

* replace @zeit/git-hooks with husky

* remove unnecessary script

* fix eslint errors

* trigger tests

* fix fixable errors

* fix fixable errors (bis)

* revert two changes
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.

[now-cli] git hooks don't work anymore
6 participants