Skip to content

Build: Enable reportUnusedDisableDirectives in ESLint #4520

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

Merged
merged 2 commits into from
Apr 20, 2020

Conversation

edg2s
Copy link
Contributor

@edg2s edg2s commented Oct 17, 2019

Summary

The reportUnusedDisableDirectives option in ESLint will report an error when in inline disable directive is no longer required, such as what happened gh-4095.

Checklist

Gruntfile.js Outdated
@@ -77,7 +77,8 @@ module.exports = function( grunt ) {
options: {

// See https://github.com/sindresorhus/grunt-eslint/issues/119
quiet: true
quiet: true,
reportUnusedDisableDirectives: true
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to configure in the ESLint configuration file instead of here?

@mgol
Copy link
Member

mgol commented Oct 17, 2019

I like it. One question.

@mgol
Copy link
Member

mgol commented Nov 18, 2019

@edg2s Do you want to update it or should we take over?

@edg2s
Copy link
Contributor Author

edg2s commented Apr 4, 2020

Adding reportUnusedDisableDirectives in the config was only added in ESLint 6.3.0. This repo currently only requires version 6.0.1 (via grunt-eslint 22.0.0).

@mgol
Copy link
Member

mgol commented Apr 4, 2020

@edg2s We can update ESLint if that helps, I don’t mind including it in a PR.

@mgol
Copy link
Member

mgol commented Apr 7, 2020

@edg2s You said before this doesn't work with the currently used ESLint version. Did anything change?

@edg2s
Copy link
Contributor Author

edg2s commented Apr 7, 2020

Sorry, I assumed you would update ESLint separately. I can do it here though.

@mgol
Copy link
Member

mgol commented Apr 7, 2020

@edg2s I've noticed grunt-eslint has been already updated on master in November, it's just that your branch is based on an extremely old version of master. Can you please rebase over latest master?

@edg2s edg2s force-pushed the eslint-unused-directives branch from 5e8514c to d7a6ac6 Compare April 7, 2020 16:37
@edg2s
Copy link
Contributor Author

edg2s commented Apr 8, 2020

Done.

@mgol mgol added Build Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. Needs review labels Apr 8, 2020
@mgol mgol removed Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. Needs review labels Apr 20, 2020
@mgol mgol changed the title eslint: Enable reportUnusedDisableDirectives Build: Enable reportUnusedDisableDirectives in ESLint Apr 20, 2020
@mgol mgol merged commit 46f9810 into jquery:master Apr 20, 2020
mgol pushed a commit that referenced this pull request Apr 20, 2020
This forbids unnecessary `eslint-disable` comments.

Ref gh-4095
Closes gh-4520

(cherry picked from 46f9810)
@edg2s edg2s deleted the eslint-unused-directives branch April 20, 2020 19:49
@mgol mgol added this to the 3.5.1 milestone Apr 20, 2020
@mgol
Copy link
Member

mgol commented Apr 20, 2020

I merged the PR to both master & 3.x-stable and, unfortunately, only afterwards I noticed:

  1. This doesn't error but only print warnings; those warnings are silenced by grunt eslint and they get only printed if you run node_modules/.bin/eslint . directly.
  2. there's one eslint-disable comment that is legitimate but we still want to keep it - it's above the version definition because in some custom compilations that string may get large and we validate the build jQuery file with ESLint as well.

I'm not sure how to proceed here due to the above. We can catch some things through these warnings but only when calling the ESLint binary directly and we have to ignore at least this one max-len warning.

@dmethvin
Copy link
Member

Seems to be a common-but-not-enough request: eslint/eslint#12703

The workaround they suggest is --max-warnings 0 assuming we don't get warnings we want to ignore.

@edg2s
Copy link
Contributor Author

edg2s commented Apr 21, 2020

A couple of options:

  1. Remove the directive, and disable max-len in dist/.eslintrc.json
  2. Have the build script that swaps out @Version insert the directive (and only if the resulting line is longer than 100 chars).

@mgol
Copy link
Member

mgol commented Apr 21, 2020

@dmethvin Their reasoning sounds reasonable. We could work with it only if we pinned our ESLint version so that patch updates don't make our build fail. Currently we have it pinned via package-lock.json but I'd rather have it explicit in the package.json if possible.

@edg2s I'd go for the first option; way smaller complexity. This doesn't resolve the issue that grunt eslint doesn't print the warnings but we can leave that for a separate PR.

@edg2s
Copy link
Contributor Author

edg2s commented Apr 21, 2020

Yeah, you would have to use it in combination with max-warnings and version pinning.

edg2s added a commit to edg2s/jquery that referenced this pull request Apr 21, 2020
This disable-directive only applies to the built version, so put
it in /dist. This avoids a warning about an unused directive in the
source version.

Follow-up to jquery#4520
@edg2s
Copy link
Contributor Author

edg2s commented Apr 21, 2020

Another issue is that grunt-eslint is giving use warnings for files that listed in .eslintignore. In the upstream issue there are some solutions that involve parsing the ignore file, but that can be done more cleanly by just fetching the parsed results from CLIEngine:

src: [ "src/**/*.js", "Gruntfile.js", "test/**/*.js", "build/**/*.js" ]

	// Ignore files from .eslintignore
	// See https://github.com/sindresorhus/grunt-eslint/issues/119
	.concat(
		new CLIEngine()
			.getConfigForFile( "Gruntfile.js" )
			.ignorePatterns.map( p => "!" + p )
	)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy