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

Linting ignored files triggers a warning #119

Open
markelog opened this issue May 10, 2016 · 8 comments
Open

Linting ignored files triggers a warning #119

markelog opened this issue May 10, 2016 · 8 comments

Comments

@markelog
Copy link

markelog commented May 10, 2016

Duplicate of #22, but despite that issue being "fixed" it is still reproducible.

Comment #22 (comment) wasn't answered, so re-creating it here, with hopes to clarify plugin current state.

Thank you.

@lukeapage
Copy link

I have the same problem.

I tried applying the fix from here: eslint/eslint#5623 (comment)

But if I specify path/ I get everything ignored (no idea whats going on, it still takes 27 seconds and then reports nothing?), if I specify path/**/*.js I get the warnings I don't want. The work-around I am using is to disable warnings.

@StevenACoffman
Copy link

StevenACoffman commented Nov 18, 2016

Yeah, this is actually a bit non-intuitive and might be worthy of documentation.
This isn't a bug in grunt-eslint, but a feature of eslint. Their policy is ignoring any explicitly included file is a warning.

The solution is to not include them in the first place:

"target": {
     "src": [
           "files/*/js/**/*.js",
           "!files/*/js/*.min.js",
           "!files/js/**/*.js",
           "!files/*/js/*.js",
           "!files/shared/js/vendor/**/*.js",
           "!files/shared/js/found*/*.js",
           "!files/bolt/**/*.js",
           "!files/clean/js/codemirror/**/*.js",
           "!files/clean/js/vendor/**/*.js",
           "!files/clean/js/image-viewer_depricated/**/*.js",
           "!files/clean/js/slick/**/*.js",
           "!files/my-lists/**/*.js",
           "!files/jv1/**/*.js",
           "!files/testTarget/**/*.js",
           "!files/jstor/**/*.js",
           "!files/ui-guide/js/views/run_prettify.js"
     ]
  }

The better solution is to not need to exclude them because vendor files and dependencies aren't organized in the same tree. But this is the real world so use the above. 😉

@superclarkk
Copy link

@markelog Can this be closed? The eslint behaviour is (currently) "by design".

Whereas grunt-eslint is a grunt plugin. If you need to ignore files, then use grunt's globbing patterns, as @StevenACoffman has suggested.

@mgol
Copy link

mgol commented Dec 13, 2016 via email

@jscharett
Copy link

I second utilizing the CLIEngine if possible. Adding a list of source patterns not to lint appears to greatly reduce performance.

@lukas-gitl
Copy link

Hacky and dirty but satisfying workaround :)

// fetch all files we want to ignore
  const eslintignore = grunt.file.read(".eslintignore").split("\n").map(
    e => e.trim()
  ).filter(
    e => e !== "" && !e.startsWith("#")
  ).map(e => `!${e}`);

Then below use:

      target: [
        '**'
      ].concat(eslintignore)

@simlu
Copy link

simlu commented Nov 12, 2017

Improved to allow for in-line comments as:

target: [
  '**'
].concat(grunt.file.read(".eslintignore").split("\n")
  .map(e => e.split("#", 1)[0].trim()).filter(e => e !== "")
  .map(e => `!${e}`))

@GreenRaccoon23
Copy link

I figured out how to use @simlu's workaround for a package/repo which has multiple eslint configurations.

Say a repo has this file structure:

  • root
    • .eslintrc.js
    • .eslintignore
    • public
      • .eslintrc.js
      • .eslintignore

This is an example of how to configure grunt-eslint to use both sets of eslint files:

Code
var Path = require('path');

function trimComments(lines) {
	return lines.map(function(line) {
		var parts = line.split('#', 1);
		var noncomment = parts[0];
		// var comment = parts[1];
		return noncomment;
	});
}

function trimWhitespace(lines) {
	return lines.map(function(line) {
		return line.trim();
	});
}

function rejectBlank(lines) {
	return lines.filter(function(line) {
		var isBlank = (line === '');
		return !isBlank;
	});
}

function prependDir(lines, dpath) {
	return lines.map(function(line) {
		var isNegater = line.startsWith('!');
		return (isNegater)
			? prependToNegater(line, dpath)
			: prependToMatcher(line, dpath);
	});
}

function prependToNegater(line, dpath) {
	var fpath = line.slice(1);
	var joined = Path.join(dpath, fpath);

	return `!${joined}`;
}

function prependToMatcher(line, dpath) {
	var fpath = line;
	var joined = Path.join(dpath, fpath);

	return joined;
}

function invertGlobs(lines) {
	return lines.map(function(line) {
		var isNegater = line.startsWith('!');
		return (isNegater) ? line.slice(1) : `!${line}`;
	});
}

module.exports = function(grunt) {

	function ignoreFile(fpath) {

		var dpath = Path.dirname(fpath);
		var content = grunt.file.read(fpath);

		var lines = content.split('\n');
		lines = trimComments(lines);
		lines = trimWhitespace(lines);
		lines = rejectBlank(lines);
		lines = prependDir(lines, dpath);
		lines = invertGlobs(lines);

		return lines;
	}

	grunt.config('eslint', {
		backend: {
			options: {
				configFile: '.eslintrc.js',
				ignore: false // suppress warnings when files are being ignored
			},
			src: [
				'**/*.js',
				...ignoreFile('.eslintignore') // but still ignore files
			]
		},
		frontend: {
			options: {
				configFile: 'public/.eslintrc.js',
				ignore: false // suppress warnings when files are being ignored
			},
			src: [
				'public/**/*.js',
				...ignoreFile('public/.eslintignore') // but still ignore files
			]
		}
	});

	grunt.loadNpmTasks('grunt-eslint');
};

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

No branches or pull requests

9 participants