From c1d5c8bf95eae40f5bc1324d6dd53c9be7c745b1 Mon Sep 17 00:00:00 2001 From: Mark Larah Date: Wed, 17 Aug 2016 01:36:33 +0100 Subject: [PATCH 1/3] Added -l cli option to allow multiple in place cli inputs --- bin/cli.js | 56 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 23 deletions(-) mode change 100644 => 100755 bin/cli.js diff --git a/bin/cli.js b/bin/cli.js old mode 100644 new mode 100755 index 351c33a..1ed5ae4 --- a/bin/cli.js +++ b/bin/cli.js @@ -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)) } From 75ba27aa7c728a6b3672423fdad1a639f9a5aa4d Mon Sep 17 00:00:00 2001 From: Ivan Sosnin Date: Wed, 24 Aug 2016 09:33:25 +0500 Subject: [PATCH 2/3] Support for length-zero-no-unit (#189) * Add length-zero-no-unit implementation * Add test * Bugfix --- README.md | 1 + lib/formatValues.js | 5 +++++ test/stylelint/length-zero-no-unit/.stylelintrc | 5 +++++ test/stylelint/length-zero-no-unit/length-zero-no-unit.css | 4 ++++ .../length-zero-no-unit/length-zero-no-unit.out.css | 4 ++++ 5 files changed, 19 insertions(+) create mode 100644 test/stylelint/length-zero-no-unit/.stylelintrc create mode 100644 test/stylelint/length-zero-no-unit/length-zero-no-unit.css create mode 100644 test/stylelint/length-zero-no-unit/length-zero-no-unit.out.css diff --git a/README.md b/README.md index f3fc484..814c957 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/lib/formatValues.js b/lib/formatValues.js index f08809b..27ae300 100644 --- a/lib/formatValues.js +++ b/lib/formatValues.js @@ -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) diff --git a/test/stylelint/length-zero-no-unit/.stylelintrc b/test/stylelint/length-zero-no-unit/.stylelintrc new file mode 100644 index 0000000..194b6e6 --- /dev/null +++ b/test/stylelint/length-zero-no-unit/.stylelintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "length-zero-no-unit": true + } +} diff --git a/test/stylelint/length-zero-no-unit/length-zero-no-unit.css b/test/stylelint/length-zero-no-unit/length-zero-no-unit.css new file mode 100644 index 0000000..94c1094 --- /dev/null +++ b/test/stylelint/length-zero-no-unit/length-zero-no-unit.css @@ -0,0 +1,4 @@ +div { + height: 0px; + width: 10px; +} diff --git a/test/stylelint/length-zero-no-unit/length-zero-no-unit.out.css b/test/stylelint/length-zero-no-unit/length-zero-no-unit.out.css new file mode 100644 index 0000000..4b79e44 --- /dev/null +++ b/test/stylelint/length-zero-no-unit/length-zero-no-unit.out.css @@ -0,0 +1,4 @@ +div { + height: 0; + width: 10px; +} From 94e297e9a91df9d8ea27a9035baaebba2f96f228 Mon Sep 17 00:00:00 2001 From: Juga Paazmaya Date: Wed, 24 Aug 2016 14:58:44 +0300 Subject: [PATCH 3/3] Drop Node.js v0.12 :see_no_evil: --- .travis.yml | 1 - index.js | 18 +++++++++--------- package.json | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 67e1119..1d0ad98 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ sudo: false language: node_js node_js: - - "0.12" - "4" - "6" diff --git a/index.js b/index.js index f7f63d5..f56a3ef 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,15 @@ -var postcss = require('postcss') -var scss = require('postcss-scss') +const postcss = require('postcss') +const scss = require('postcss-scss') -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) { diff --git a/package.json b/package.json index afd2b88..ac46df9 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "url": "git://github.com/morishitter/stylefmt/git" }, "engines": { - "node": ">=0.12.0" + "node": ">=4.2.0" }, "keywords": [ "css",