-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace gruntify-eslint with basic eslint-cli wrapper
- Loading branch information
Showing
6 changed files
with
97 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
/optimize | ||
/src/fixtures/vislib/mock_data | ||
/src/ui/public/angular-bootstrap | ||
/test/fixtures/scenarios | ||
/src/core_plugins/console/public/webpackShims | ||
/src/core_plugins/console/public/tests/webpackShims | ||
/src/core_plugins/timelion/bower_components | ||
/src/core_plugins/timelion/vendor_components | ||
test/fixtures/scenarios | ||
optimize | ||
test/fixtures/scenarios |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
var resolve = require('path').resolve; | ||
import { resolve } from 'path'; | ||
module.exports = grunt => ({ | ||
options: { | ||
paths: [ | ||
'Gruntfile.js', | ||
'bin', | ||
'config', | ||
'src', | ||
'tasks', | ||
'test', | ||
'utilities', | ||
], | ||
}, | ||
|
||
module.exports = function (grunt) { | ||
return { | ||
// just lint the source dir | ||
source: { | ||
options: { | ||
cache: resolve(grunt.config.get('root'), '.eslint.fixSource.cache') | ||
}, | ||
source: { | ||
options: { | ||
cache: resolve(grunt.config.get('root'), '.eslint.fixSource.cache') | ||
} | ||
}, | ||
|
||
files: { | ||
src: '<%= lintThese %>' | ||
} | ||
}, | ||
fixSource: { | ||
options: { | ||
cache: resolve(grunt.config.get('root'), '.eslint.fixSource.cache'), | ||
fix: true | ||
} | ||
}, | ||
|
||
// lint the source and fix any fixable errors | ||
fixSource: { | ||
options: { | ||
cache: resolve(grunt.config.get('root'), '.eslint.fixSource.cache'), | ||
fix: true | ||
}, | ||
|
||
files: { | ||
src: '<%= lintThese %>' | ||
} | ||
}, | ||
|
||
staged: {} | ||
}; | ||
}; | ||
staged: { | ||
options: { | ||
paths: null // overridden by lintStagedFiles task | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { CLIEngine } from 'eslint'; | ||
|
||
const OPTION_DEFAULTS = { | ||
paths: null, | ||
cache: null, | ||
fix: false | ||
}; | ||
|
||
module.exports = grunt => { | ||
grunt.registerMultiTask('eslint',function () { | ||
const options = this.options(OPTION_DEFAULTS); | ||
|
||
if (!options.paths) { | ||
grunt.fatal(new Error('No eslint.options.paths specified')); | ||
return; | ||
} | ||
|
||
const cli = new CLIEngine({ | ||
cache: options.cache, | ||
fix: options.fix, | ||
cwd: grunt.config.get('root'), | ||
}); | ||
|
||
const report = cli.executeOnFiles(options.paths); | ||
|
||
// output fixes to disk | ||
if (options.fix) { | ||
CLIEngine.outputFixes(report); | ||
} | ||
|
||
// log the formatted linting report | ||
const formatter = cli.getFormatter(); | ||
|
||
const errTypes = []; | ||
if (report.errorCount > 0) errTypes.push('errors'); | ||
if (report.warningCount > 0) errTypes.push('warning'); | ||
if (!errTypes.length) return; | ||
|
||
grunt.log.write(formatter(report.results)); | ||
grunt.fatal(`eslint ${errTypes.join(' & ')}`); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,40 @@ | ||
import { resolve } from 'path'; | ||
import { isStaged, getFilename } from './utils/files_to_commit'; | ||
import { CLIEngine } from 'eslint'; | ||
import minimatch from 'minimatch'; | ||
|
||
const root = resolve(__dirname, '..'); | ||
|
||
export default function (grunt) { | ||
grunt.registerTask('lintStagedFiles', function () { | ||
grunt.task.requires('collectFilesToCommit'); | ||
|
||
// match these patterns | ||
var patterns = grunt.config.get('eslint.source.files.src'); | ||
if (!patterns) grunt.fail.warn('eslint file pattern is not defined'); | ||
// convert eslint paths to globs | ||
const cli = new CLIEngine(); | ||
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 files = grunt.config | ||
.get('filesToCommit') | ||
.filter(isStaged) | ||
.map(getFilename) | ||
.map(file => resolve(root, file)) | ||
.filter(file => grunt.file.isMatch(patterns, file)); | ||
.filter(file => { | ||
if (!sourcePathRegexps.some(re => file.match(re))) { | ||
return false; | ||
} | ||
|
||
if (cli.isPathIgnored(file)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}); | ||
|
||
grunt.config.set('eslint.staged.files.src', files); | ||
grunt.config.set('eslint.staged.options.paths', files); | ||
grunt.task.run(['eslint:staged']); | ||
}); | ||
} |