Permalink
Browse files

Merge upstream/๐Ÿท

  • Loading branch information...
2 parents 5767b97 + 2f921da commit 943c8297a7b5a60fd3de7fa99a98b8441c16f779 @paazmaya paazmaya committed Aug 25, 2016
View
@@ -1,7 +1,6 @@
sudo: false
language: node_js
node_js:
- - "0.12"
- "4"
- "6"
script:
View
@@ -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)
View
56 bin/cli.js 100644 โ†’ 100755
@@ -17,6 +17,7 @@ var argv = minimist(process.argv.slice(2), {
h: 'help',
v: 'version',
d: 'diff',
+ l: 'list',
R: 'recursive',
c: 'config'
}
@@ -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')
@@ -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]
@@ -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)])
@@ -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))
}
View
@@ -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) {
View
@@ -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()
@@ -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)
View
@@ -15,7 +15,7 @@
"url": "git://github.com/morishitter/stylefmt/git"
},
"engines": {
- "node": ">=0.12.0"
+ "node": ">=4.2.0"
},
"keywords": [
"css",
@@ -0,0 +1,5 @@
+{
+ "rules": {
+ "length-zero-no-unit": true
+ }
+}
@@ -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.