Skip to content

Commit

Permalink
Merge upstream/:pig:
Browse files Browse the repository at this point in the history
  • Loading branch information
paazmaya committed Aug 25, 2016
2 parents 5767b97 + 2f921da commit 943c829
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 33 deletions.
1 change: 0 additions & 1 deletion .travis.yml
@@ -1,7 +1,6 @@
sudo: false
language: node_js
node_js:
- "0.12"
- "4"
- "6"
script:
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -336,6 +336,7 @@ stylefmt supports the following stylelint rules:
- [declaration-colon-space-after](https://github.com/stylelint/stylelint/tree/master/src/rules/declaration-colon-space-after)
- [declaration-colon-space-before](https://github.com/stylelint/stylelint/tree/master/src/rules/declaration-colon-space-before)
- [indentation](https://github.com/stylelint/stylelint/tree/master/src/rules/indentation)
- [length-zero-no-unit](https://github.com/stylelint/stylelint/tree/master/src/rules/length-zero-no-unit)
- [selector-combinator-space-after](https://github.com/stylelint/stylelint/tree/master/src/rules/selector-combinator-space-after)
- [selector-combinator-space-before](https://github.com/stylelint/stylelint/tree/master/src/rules/selector-combinator-space-before)
- [selector-list-comma-newline-after](https://github.com/stylelint/stylelint/tree/master/src/rules/selector-list-comma-newline-after)
Expand Down
56 changes: 33 additions & 23 deletions bin/cli.js 100644 → 100755
Expand Up @@ -17,6 +17,7 @@ var argv = minimist(process.argv.slice(2), {
h: 'help',
v: 'version',
d: 'diff',
l: 'list',
R: 'recursive',
c: 'config'
}
Expand All @@ -37,6 +38,7 @@ if (argv.h) {
console.log('Options:')
console.log('')
console.log(' -d, --diff output diff against original file')
console.log(' -l, --list format list of space seperated files in place')
console.log(' -R, --recursive format files recursively')
console.log(' -c, --config path to a specific configuration file (JSON, YAML, or CommonJS)')
console.log(' -v, --version output the version number')
Expand All @@ -50,7 +52,10 @@ if (argv.c) {
options.config = argv.c
}

if (argv._[0]) {
if (argv.l) {
var files = [argv.l].concat(argv._)
processMultipleFiles(files)
} else if (argv._[0]) {
var input = argv._[0]
var output = argv._[1] || argv._[0]

Expand All @@ -77,28 +82,8 @@ if (argv._[0]) {
var recursive = require('recursive-readdir')

recursive(argv.R, function (err, files) {
files.forEach(function (file) {
var fullPath = path.resolve(process.cwd(), file)
if (!isCss(fullPath)) {
return
}

var css = fs.readFileSync(fullPath, 'utf-8')

postcss([stylefmt(options)])
.process(css, { syntax: scss })
.then(function (result) {
var formatted = result.css
if (css !== formatted) {
fs.writeFile(fullPath, formatted, function (err) {
if (err) {
throw err
}
})
}
})
})
})
processMultipleFiles(files)
})
} else {
stdin(function (css) {
postcss([stylefmt(options)])
Expand All @@ -110,6 +95,31 @@ if (argv._[0]) {
}


function processMultipleFiles (files) {
files.forEach(function (file) {
var fullPath = path.resolve(process.cwd(), file)
if (!isCss(fullPath)) {
return
}

var css = fs.readFileSync(fullPath, 'utf-8')

postcss([stylefmt(options)])
.process(css, { syntax: scss })
.then(function (result) {
var formatted = result.css
if (css !== formatted) {
fs.writeFile(fullPath, formatted, function (err) {
if (err) {
throw err
}
})
}
})
})
}


function isCss (filePath) {
return /^\.css|\.scss$/i.test(path.extname(filePath))
}
Expand Down
16 changes: 8 additions & 8 deletions index.js
@@ -1,14 +1,14 @@
var postcss = require('postcss')
const postcss = require('postcss')

var params = require('./lib/params')
var formatAtRules = require('./lib/formatAtRules')
var formatOrder = require('./lib/formatOrder')
var formatRules = require('./lib/formatRules')
var formatComments = require('./lib/formatComments')
var formatSassVariables = require('./lib/formatSassVariables')
const params = require('./lib/params')
const formatAtRules = require('./lib/formatAtRules')
const formatOrder = require('./lib/formatOrder')
const formatRules = require('./lib/formatRules')
const formatComments = require('./lib/formatComments')
const formatSassVariables = require('./lib/formatSassVariables')


var stylefmt = postcss.plugin('stylefmt', function (options) {
const stylefmt = postcss.plugin('stylefmt', function (options) {
options = options || {}

return function (root) {
Expand Down
5 changes: 5 additions & 0 deletions lib/formatValues.js
Expand Up @@ -6,6 +6,7 @@ function formatvalues (decl, stylelint) {
var isVarNotation = /var\s*\(.*\)/.test(decl.value)
var isString = /^("|').*("|')$/.test(decl.value)
var isFunctionCall = /\w+\(.+\)/.test(decl.value)
var zeroWithUnitRegex = /^0[\.0]*(?:px|r?em|ex|ch|vh|vw|cm|mm|in|pt|pc|vmin|vmax)/g

if (decl.raws.value) {
decl.raws.value.raw = decl.raws.value.raw.trim()
Expand Down Expand Up @@ -58,6 +59,10 @@ function formatvalues (decl, stylelint) {
decl.value = decl.value.replace(/\(\s*/g, '(')
decl.value = decl.value.replace(/\s*\)/g, ')')

if (stylelint && stylelint['length-zero-no-unit'] === true) {
decl.value = decl.value.replace(zeroWithUnitRegex, '0')
}

decl.value = formatColors(decl.value, stylelint)
decl.value = formatTransforms(decl.value)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -15,7 +15,7 @@
"url": "git://github.com/morishitter/stylefmt/git"
},
"engines": {
"node": ">=0.12.0"
"node": ">=4.2.0"
},
"keywords": [
"css",
Expand Down
5 changes: 5 additions & 0 deletions test/stylelint/length-zero-no-unit/.stylelintrc
@@ -0,0 +1,5 @@
{
"rules": {
"length-zero-no-unit": true
}
}
4 changes: 4 additions & 0 deletions test/stylelint/length-zero-no-unit/length-zero-no-unit.css
@@ -0,0 +1,4 @@
div {
height: 0px;
width: 10px;
}
@@ -0,0 +1,4 @@
div {
height: 0;
width: 10px;
}

0 comments on commit 943c829

Please sign in to comment.