Skip to content

Commit

Permalink
🔥 Remove redundant import and export
Browse files Browse the repository at this point in the history
  • Loading branch information
kghugo committed Aug 4, 2020
1 parent 8444cd4 commit 1289fdd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
14 changes: 4 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
let postcss = require('postcss')
const postcss = require('postcss')

const {
filterIdenticalValues,
hasWrappedInRFS,
isIncluded,
shouldBeTransformed
} = require('./utilities/helper.js')

Expand All @@ -24,22 +21,19 @@ module.exports = postcss.plugin('postcss-rfs-autopilot', ({
'*'
],
excludedSelectors: excludedSelectors || [],
includedUnits: includedUnits || [ 'px', 'rem' ],
includedUnits: includedUnits || ['px', 'rem'],
excludedUnits: excludedUnits || []
}
//Filter includedRules here with excludedRules
// Filter includedRules here with excludedRules
// options.includedRules = filterIdenticalValues(options.includedRules, options.excludedRules)
// options.includedSelectors = filterIdenticalValues(options.includedSelectors, options.excludedSelectors)
// options.includedUnits = filterIdenticalValues(options.includedUnits, options.excludedUnits)

return (root, result) => {

root.walkDecls((decl) => {

if ( shouldBeTransformed(decl, options) ) {
if (shouldBeTransformed(decl, options)) {
decl.value = `rfs(${decl.value})`
}

})
}
})
27 changes: 10 additions & 17 deletions utilities/helper.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,51 @@
const {
options
} = require('../index.js')

const chalk = require('chalk');
const chalk = require('chalk')

const hasWrappedInRFS = (decl) => /^rfs/g.test(decl.value)

const isIncluded = (decl, inclusionRules) => {
if (inclusionRules.includes('*')) {
return true;
return true
}

return inclusionRules.some(unit => RegExp(unit).test(decl));
return inclusionRules.some(unit => RegExp(unit).test(decl))
}

const log = (msg, msgType) => {
switch (msgType) {
case 'success':
console.log(chalk.green(msg))
break;
break

case 'error':
console.log(chalk.red(msg))
break;
break
default:

}
}

const shouldBeTransformed = (decl, options) => {

if (hasWrappedInRFS(decl)) {
return false
}

const inclusionRules = [ options.includedRules, options.includedSelectors, options.includedUnits]
const exclusionRules = [ options.excludedRules, options.excludedSelectors, options.excludedUnits]
const inclusionRules = [options.includedRules, options.includedSelectors, options.includedUnits]
const exclusionRules = [options.excludedRules, options.excludedSelectors, options.excludedUnits]
const validationValues = [decl.prop, decl.parent.selector, decl.value]

for(const [index, value] of validationValues.entries() ){
if(! isIncluded(value, inclusionRules[index]) || isIncluded(value, exclusionRules[index]) ){
for (const [index, value] of validationValues.entries()) {
if (!isIncluded(value, inclusionRules[index]) || isIncluded(value, exclusionRules[index])) {
log(`${decl.parent.selector}{ ${decl.prop}: ${decl.value} } has been excluded`, 'error')
return false
}
}

log(`${decl.parent.selector}{ ${decl.prop}: ${decl.value} } has been wrapped with rfs()`, 'success')

return true
}

module.exports = {
hasWrappedInRFS,
isIncluded,
filterIdenticalValues,
shouldBeTransformed
}

0 comments on commit 1289fdd

Please sign in to comment.