Skip to content

Commit

Permalink
fix: add boolean to toggle between check and apply
Browse files Browse the repository at this point in the history
  • Loading branch information
varl committed Apr 23, 2019
1 parent 624b626 commit 663c90a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/cmds/js_cmds/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exports.handler = argv => {
log.debug(`Root directory: ${root}`)

const codeFiles = selectFiles(files, all, root)
const report = runner(codeFiles)
const report = runner(codeFiles, true)

report.summary()

Expand Down
14 changes: 7 additions & 7 deletions src/tools/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const TOOLS = [
* @param {string} path to the file to run tools on
* @param {boolean} if the tool should apply fixes
*/
function runTools(file, fix) {
function runTools(file, apply = false) {
const p = path.relative(process.cwd(), file)
const text = readFile(file)

Expand All @@ -34,7 +34,7 @@ function runTools(file, fix) {

perf.start('exec-file')
for (const tool of TOOLS) {
const result = tool(file, source, fix)
const result = tool(file, source, apply)

source = result.output
messages = messages.concat(result.messages)
Expand All @@ -49,9 +49,9 @@ function runTools(file, fix) {
}
}

function exec(files) {
function exec(files, apply = false) {
perf.start('exec-all-files')
const report = files.map(f => runTools(f, true))
const report = files.map(f => runTools(f, apply))
log.debug(`${files.length} file(s): ${perf.end('exec-all-files').summary}`)

return report
Expand Down Expand Up @@ -102,22 +102,22 @@ function fix(report) {
return fixed
}

exports.runner = files => {
exports.runner = (files, apply = false) => {
const js = jsFiles(files)
log.debug(`Files to operate on:\n${js}`)

const report = exec(js)
const report = exec(js, apply)
const violations = getViolations(report)
const hasViolations = violations.length > 0

log.debug(`Violations: ${violations.length}`)

return {
files: js,
summary: () => print(report, violations),
fix: () => fix(report),
violations,
hasViolations,
files: js,
report,
}
}

0 comments on commit 663c90a

Please sign in to comment.