mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
Lint untracked files with yarn linc (#11665)
* Lint untracked files with yarn linc (#11646) * Run prettier on untracked files * Unify code for listing changed files into shared utility
This commit is contained in:
committed by
Dan Abramov
parent
ff2d50f144
commit
e140c5a4e2
@@ -11,9 +11,9 @@
|
||||
|
||||
const chalk = require('chalk');
|
||||
const glob = require('glob');
|
||||
const execFileSync = require('child_process').execFileSync;
|
||||
const prettier = require('prettier');
|
||||
const fs = require('fs');
|
||||
const listChangedFiles = require('../shared/listChangedFiles');
|
||||
|
||||
const mode = process.argv[2] || 'check';
|
||||
const shouldWrite = mode === 'write' || mode === 'write-changed';
|
||||
@@ -56,28 +56,7 @@ const config = {
|
||||
},
|
||||
};
|
||||
|
||||
function exec(command, args) {
|
||||
console.log('> ' + [command].concat(args).join(' '));
|
||||
var options = {
|
||||
cwd: process.cwd(),
|
||||
env: process.env,
|
||||
stdio: 'pipe',
|
||||
encoding: 'utf-8',
|
||||
};
|
||||
return execFileSync(command, args, options);
|
||||
}
|
||||
|
||||
var mergeBase = exec('git', ['merge-base', 'HEAD', 'master']).trim();
|
||||
var changedFiles = new Set(
|
||||
exec('git', [
|
||||
'diff',
|
||||
'-z',
|
||||
'--name-only',
|
||||
'--diff-filter=ACMRTUB',
|
||||
mergeBase,
|
||||
]).match(/[^\0]+/g)
|
||||
);
|
||||
|
||||
var changedFiles = listChangedFiles();
|
||||
let didWarn = false;
|
||||
let didError = false;
|
||||
Object.keys(config).forEach(key => {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright (c) 2013-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const execFileSync = require('child_process').execFileSync;
|
||||
|
||||
const exec = (command, args) => {
|
||||
console.log('> ' + [command].concat(args).join(' '));
|
||||
var options = {
|
||||
cwd: process.cwd(),
|
||||
env: process.env,
|
||||
stdio: 'pipe',
|
||||
encoding: 'utf-8',
|
||||
};
|
||||
return execFileSync(command, args, options);
|
||||
};
|
||||
const execGitCmd = args =>
|
||||
exec('git', args)
|
||||
.trim()
|
||||
.toString()
|
||||
.split('\n');
|
||||
|
||||
const mergeBase = execGitCmd(['merge-base', 'HEAD', 'master']);
|
||||
|
||||
const listChangedFiles = () => {
|
||||
return new Set([
|
||||
...execGitCmd(['diff', '--name-only', '--diff-filter=ACMRTUB', mergeBase]),
|
||||
...execGitCmd(['ls-files', '--others', '--exclude-standard']),
|
||||
]);
|
||||
};
|
||||
|
||||
module.exports = listChangedFiles;
|
||||
+3
-16
@@ -8,22 +8,9 @@
|
||||
'use strict';
|
||||
|
||||
const lintOnFiles = require('../eslint');
|
||||
const execFileSync = require('child_process').execFileSync;
|
||||
const mergeBase = execFileSync('git', ['merge-base', 'HEAD', 'master'], {
|
||||
stdio: 'pipe',
|
||||
encoding: 'utf-8',
|
||||
}).trim();
|
||||
const changedFiles = execFileSync(
|
||||
'git',
|
||||
['diff', '--name-only', '--diff-filter=ACMRTUB', mergeBase],
|
||||
{
|
||||
stdio: 'pipe',
|
||||
encoding: 'utf-8',
|
||||
}
|
||||
)
|
||||
.trim()
|
||||
.toString()
|
||||
.split('\n');
|
||||
const listChangedFiles = require('../shared/listChangedFiles');
|
||||
|
||||
const changedFiles = [...listChangedFiles()];
|
||||
const jsFiles = changedFiles.filter(file => file.match(/.js$/g));
|
||||
|
||||
const report = lintOnFiles(jsFiles);
|
||||
|
||||
Reference in New Issue
Block a user