We limit the amount of moving parts when it comes to parsing our staged files in git by reusing the files_to_commit utility rather than the now-defunct collectStagedFiles task.
24 lines
743 B
JavaScript
24 lines
743 B
JavaScript
import { resolve } from 'path';
|
|
import { isStaged, getFilename } from './utils/files_to_commit';
|
|
|
|
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');
|
|
|
|
const files = grunt.config
|
|
.get('filesToCommit')
|
|
.filter(isStaged)
|
|
.map(getFilename)
|
|
.map(file => resolve(root, file))
|
|
.filter(file => grunt.file.isMatch(patterns, file));
|
|
|
|
grunt.config.set('eslint.staged.files.src', files);
|
|
grunt.task.run(['eslint:staged']);
|
|
});
|
|
}
|