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

[5.x] [grunt/eslint] fix precommit linting #9532

Merged
merged 1 commit into from
Dec 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions tasks/lint_staged_files.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { resolve } from 'path';
import { extname, resolve, relative } from 'path';
import { isStaged, getFilename } from './utils/files_to_commit';
import { CLIEngine } from 'eslint';
import { red, blue } from 'ansicolors';
import minimatch from 'minimatch';

const root = resolve(__dirname, '..');
Expand All @@ -14,20 +15,25 @@ export default function (grunt) {
const eslintSourcePaths = grunt.config.get('eslint.options.paths');
if (!eslintSourcePaths) grunt.fail.warn('eslint.options.paths is not defined');

const sourcePathRegexps = cli.resolveFileGlobPatterns(eslintSourcePaths)
.map(glob => minimatch.makeRe(glob));
const sourcePathGlobs = cli.resolveFileGlobPatterns(eslintSourcePaths);

const files = grunt.config
.get('filesToCommit')
.filter(isStaged)
.map(getFilename)
.map(file => resolve(root, file))
.map(file => relative(root, resolve(file))) // resolve to pwd, then get relative from the root
.filter(file => {
if (!sourcePathRegexps.some(re => file.match(re))) {
if (!sourcePathGlobs.some(glob => minimatch(file, glob))) {
if (extname(file) === '.js') {
grunt.log.writeln(`${red('WARNING:')} ${file} not selected by grunt eslint config`);
}
return false;
}

if (cli.isPathIgnored(file)) {
if (extname(file) === '.js') {
grunt.log.writeln(`${blue('DEBUG:')} ${file} ignored by .eslintignore`);
}
return false;
}

Expand Down