mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Check that all new files are snake cased
We removed the snake case check during precommit because it was interfering with us getting features merged when dealing with legacy files, but we do want to verify that any new files added have snake cased names.
This commit is contained in:
parent
a42f29fe23
commit
acded081fa
4 changed files with 67 additions and 0 deletions
18
tasks/check_added_filenames.js
Normal file
18
tasks/check_added_filenames.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { isAdded, getFilename } from './utils/files_to_commit';
|
||||
|
||||
export default function registerCheckAddedFilenames(grunt) {
|
||||
grunt.registerTask('checkAddedFilenames', function () {
|
||||
grunt.task.requires('collectFilesToCommit');
|
||||
|
||||
const invalid = grunt.config
|
||||
.get('filesToCommit')
|
||||
.filter(isAdded)
|
||||
.map(getFilename)
|
||||
.filter(name => name.match(/[A-Z \-]/))
|
||||
.reduce((all, name) => `${all} ${name}\n`, '');
|
||||
|
||||
if (invalid) {
|
||||
grunt.fail.fatal(`Filenames must use snake_case.\n${invalid}`);
|
||||
}
|
||||
});
|
||||
}
|
15
tasks/collect_files_to_commit.js
Normal file
15
tasks/collect_files_to_commit.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import filesToCommit from './utils/files_to_commit';
|
||||
import { resolve } from 'path';
|
||||
|
||||
const root = resolve(__dirname, '..');
|
||||
|
||||
export default function registerCollectFilesToCommit(grunt) {
|
||||
grunt.registerTask('collectFilesToCommit', function () {
|
||||
filesToCommit(root)
|
||||
.then(files => {
|
||||
grunt.log.ok(`${files.length} files with changes to commit`);
|
||||
grunt.config.set('filesToCommit', files);
|
||||
})
|
||||
.nodeify(this.async());
|
||||
});
|
||||
};
|
|
@ -1,6 +1,8 @@
|
|||
export default function (grunt) {
|
||||
grunt.registerTask('precommit', [
|
||||
'collectFilesToCommit',
|
||||
'collectStagedFiles',
|
||||
'checkAddedFilenames',
|
||||
'lintStagedFiles'
|
||||
]);
|
||||
};
|
||||
|
|
32
tasks/utils/files_to_commit.js
Normal file
32
tasks/utils/files_to_commit.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
import SimpleGit from 'simple-git';
|
||||
import { promisify } from 'bluebird';
|
||||
|
||||
export default function filesToCommit(path) {
|
||||
const simpleGit = new SimpleGit(path);
|
||||
const gitDiff = promisify(simpleGit.diff, simpleGit);
|
||||
|
||||
return gitDiff(['--name-status', '--cached'])
|
||||
.then(output => {
|
||||
return output
|
||||
.split('\n')
|
||||
.map(line => line.trim().split('\t'))
|
||||
.filter(parts => parts.length === 2)
|
||||
.map(parts => {
|
||||
const status = parts.shift();
|
||||
const name = parts.join('\t').trim();
|
||||
return { status, name };
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export function getFilename(file) {
|
||||
return file.name;
|
||||
}
|
||||
|
||||
export function isAdded(file) {
|
||||
return file.status === 'A';
|
||||
};
|
||||
|
||||
export function isDeleted(file) {
|
||||
return file.status === 'D';
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue