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

feat: warnings in eslint #366

Closed
wants to merge 1 commit into from
Closed

feat: warnings in eslint #366

wants to merge 1 commit into from

Conversation

varl
Copy link
Contributor

@varl varl commented Mar 10, 2021

Allow d2-style to print warnings from ESLint.

Set a zero tolerance on warnings by making ESLint exit with a non-zero
code if there are any warnings.

A developer is required to either:

a) fix the warning
b) explicitly mark the code that triggered the warning with an
eslint-disable comment.

A good disable directive uses the comment syntax for ESLint:

/* eslint-disable [rule] -- [comment] */

E.g.

/* eslint-disable-next-line no-console -- we need to log here */

@varl varl requested review from amcgee and a user March 10, 2021 18:54
@@ -1,5 +1,3 @@
const SEVERITY = 2
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was always a useless magic number, swapping it out for a sane string.

Comment on lines +9 to +10
// unignore implicit rules about what types of files can be linted
ignorePatterns: ['!.*'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By default ESLint ignores all dot-files and dot-folders and node_modules/.

We lint our configuration files, so the former implicit ignore rule needs to be disabled. This does it for the common configuration, so it is still possible to override from an config that extends this one if need be.

We agree with the rule about not linting node_modules.

Allow d2-style to print warnings from ESLint.

Set a zero tolerance on warnings by making ESLint exit with a non-zero
code if there are any warnings.

A developer is required to either:

a)  fix the warning
b)  explicitly mark the code that triggered the warning with an
eslint-disable comment.

A good disable directive uses the comment syntax for ESLint:

    /* eslint-disable [rule] -- [comment] */

E.g.

    /* eslint-disable-next-line no-console -- we need to log here */
@@ -9,8 +9,8 @@ exports.eslint = ({ files = [], apply = false, config }) => {
'--no-color',
'--report-unused-disable-directives',
'--ignore',
'--quiet',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This made ESLint ignore all warnings and not print them.

'--format=unix',
'--max-warnings=0',
Copy link
Contributor Author

@varl varl Mar 10, 2021

Choose a reason for hiding this comment

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

This makes ESLint exit with a non-zero exit code when there are warnings, which will make e.g. CI and Git hook fail the lint job if there are warnings.

Copy link
Contributor Author

@varl varl Mar 10, 2021

Choose a reason for hiding this comment

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

We could make this configurable by a flag that flips between 0 (no warnings) and -1 (infinite warnings) through e.g. --[no-]warnings-allowed.

I don't see the point of doing so?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another option is to enable/disable the --quiet flag through e.g. --[no-]warn with --no-warn being the default.

That means that if a user wants to see the warnings, she would run d2-style js check --warn. It would be useful for seeing what warnings there are, but wouldn't force any actions to be taken.

It gives us the ability to introduce new rules as warnings, and then upgrade them to errors when we want to.

We could call the flag something like --future-errors.

@varl varl closed this Mar 10, 2021
@varl varl deleted the allow-warnings branch March 10, 2021 20:33
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.

1 participant