Skip to content

Commit

Permalink
fix: clean up js filter mechanism (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
varl authored and amcgee committed Mar 5, 2019
1 parent 7de5ca9 commit ece8c53
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/cmds/js_cmds/apply.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { collectJsFiles, whitelists, whitelisted } = require('../../files.js')
const { collectFiles, jsFiles } = require('../../files.js')
const log = require('@dhis2/cli-helpers-engine').reporter

const { apply_fmt } = require('../../prettier.js')
Expand Down Expand Up @@ -31,19 +31,18 @@ exports.handler = argv => {

let codeFiles
if (all) {
codeFiles = collectJsFiles(root_dir)
codeFiles = collectFiles(root_dir)
} else if (files) {
codeFiles = files
} else {
const whitelist = whitelisted(whitelists.js)
codeFiles = staged_files(root_dir).filter(whitelist)
codeFiles = staged_files(root_dir)
}

// debug information about the folders
log.debug('rootDir?', root_dir)
log.debug('codeFiles?', codeFiles)

const prettyFiles = apply_fmt(codeFiles)
const prettyFiles = apply_fmt(jsFiles(codeFiles))

if (prettyFiles.length === 0) {
log.info('No files to style.')
Expand Down
9 changes: 4 additions & 5 deletions src/cmds/js_cmds/check.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path')
const { collectJsFiles, whitelists, whitelisted } = require('../../files.js')
const { collectFiles, jsFiles } = require('../../files.js')
const log = require('@dhis2/cli-helpers-engine').reporter

const { check_fmt } = require('../../prettier.js')
Expand All @@ -24,19 +24,18 @@ exports.handler = argv => {

let codeFiles
if (all) {
codeFiles = collectJsFiles(root_dir)
codeFiles = collectFiles(root_dir)
} else if (files) {
codeFiles = files
} else {
const whitelist = whitelisted(whitelists.js)
codeFiles = staged_files(root_dir).filter(whitelist)
codeFiles = staged_files(root_dir)
}

// debug information about the folders
log.debug('rootDir?', root_dir)
log.debug('codeFiles?', codeFiles)

const prettyFiles = check_fmt(codeFiles)
const prettyFiles = check_fmt(jsFiles(codeFiles))

const success = prettyFiles.length > 0

Expand Down
6 changes: 6 additions & 0 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ function whitelisted(whitelist) {
}
}

function jsFiles(arr) {
const whitelist = whitelisted(whitelists.js)
return arr.filter(whitelist)
}

function collectJsFiles(target) {
const whitelist = whitelisted(whitelists.js)
return collectFiles(target).filter(whitelist)
Expand Down Expand Up @@ -67,6 +72,7 @@ module.exports = {
collectFiles,
collectAllFiles,
collectJsFiles,
jsFiles,
readFile,
writeFile,
whitelisted,
Expand Down

0 comments on commit ece8c53

Please sign in to comment.