From a800184cc47c7119f7d3777acbdfdf6078a0fb17 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Tue, 10 Jan 2017 11:09:48 +0100 Subject: [PATCH] Inverts some level 1 options for consistency. @alexlamsl made a good point that when we have `all` shortcut, to set all options at once, it'd be good if value given would mean the same to all options. --- README.md | 14 ++--- bin/cleancss | 8 +-- lib/optimizer/level-1/optimize.js | 14 ++--- lib/options/optimization-level.js | 6 +- test/optimizer/level-1/optimize-test.js | 48 +++++++------- test/options/optimization-level-test.js | 84 ++++++++++++------------- 6 files changed, 87 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index 0d6ccfa0..729c8838 100644 --- a/README.md +++ b/README.md @@ -119,11 +119,8 @@ Level 1 optimizations (default): ```bash cleancss -O1 one.css -cleancss -O1 keepQuotes:on;roundingPrecision:4;specialComments:1 one.css +cleancss -O1 removeQuotes:off;roundingPrecision:4;specialComments:1 one.css # `cleanupCharsets` controls `@charset` moving to the front of a stylesheet; defaults to `on` -# `keepNegativePaddings` controls negative paddings removal; defaults to `off` -# `keepQuotes` controls keeping quotes when unnecessary; defaults to `off` -# `keepWhitespace` controls keeping unused whitespace; defaults to `off` # `normalizeUrls` controls URL normalzation; default to `on` # `optimizeBackground` controls `background` property optimizatons; defaults to `on` # `optimizeBorderRadius` controls `border-radius` property optimizatons; defaults to `on` @@ -131,6 +128,9 @@ cleancss -O1 keepQuotes:on;roundingPrecision:4;specialComments:1 one.css # `optimizeFont controls `font` property optimizatons; defaults to `on` # `optimizeFontWeight` controls `font-weight` property optimizatons; defaults to `on` # `optimizeOutline` controls `outline` property optimizatons; defaults to `on` +# `removeNegativePaddings` controls removing negative paddings; defaults to `on` +# `removeQuotes` controls removing quotes when unnecessary; defaults to `on` +# `removeWhitespace` controls removing unused whitespace; defaults to `on` # `replaceMultipleZeros` contols removing redundant zeros; defaults to `on` # `replaceTimeUnits` controls replacing time units with shorter values; defaults to `on # `replaceZeroUnits` controls replacing zero values with units; defaults to `on` @@ -206,9 +206,6 @@ new CleanCSS({ level: { 1: { cleanupCharsets: true, // controls `@charset` moving to the front of a stylesheet; defaults to `true` - keepNegativePaddings: false, // controls negative paddings removal; defaults to `false` - keepQuotes: false, // controls keeping quotes when unnecessary; defaults to `false` - keepWhitespace: false, // controls keeping unused whitespace; defaults to `false` normalizeUrls: true, // controls URL normalzation; default to `true` optimizeBackground: true, // controls `background` property optimizatons; defaults to `true` optimizeBorderRadius: true, // controls `border-radius` property optimizatons; defaults to `true` @@ -216,6 +213,9 @@ new CleanCSS({ optimizeFont: true, // ontrols `font` property optimizatons; defaults to `true` optimizeFontWeight: true, // controls `font-weight` property optimizatons; defaults to `true` optimizeOutline: true, // controls `outline` property optimizatons; defaults to `true` + removeNegativePaddings: true, // controls removing negative paddings; defaults to `true` + removeQuotes: true, // controls removing quotes when unnecessary; defaults to `true` + removeWhitespace: true, // controls removing unused whitespace; defaults to `true` replaceMultipleZeros: true, // contols removing redundant zeros; defaults to `true` replaceTimeUnits: true, // controls replacing time units with shorter values; defaults to `true` replaceZeroUnits: true, // controls replacing zero values with units; defaults to `true` diff --git a/bin/cleancss b/bin/cleancss index bb11a713..645fac3d 100755 --- a/bin/cleancss +++ b/bin/cleancss @@ -38,11 +38,8 @@ commands.on('--help', function () { console.log(''); console.log(' Level 1 optimizations:'); console.log(' %> cleancss -O1 one.css'); - console.log(' %> cleancss -O1 keepQuotes:on;roundingPrecision:4;specialComments:1 one.css'); + console.log(' %> cleancss -O1 removeQuotes:off;roundingPrecision:4;specialComments:1 one.css'); console.log(' %> # `cleanupCharsets` controls `@charset` moving to the front of a stylesheet; defaults to `on`'); - console.log(' %> # `keepNegativePaddings` controls negative paddings removal; defaults to `off`'); - console.log(' %> # `keepQuotes` controls keeping quotes when unnecessary; defaults to `off`'); - console.log(' %> # `keepWhitespace` controls keeping unused whitespace; defaults to `off`'); console.log(' %> # `normalizeUrls` controls URL normalzation; default to `on`'); console.log(' %> # `optimizeBackground` controls `background` property optimizatons; defaults to `on`'); console.log(' %> # `optimizeBorderRadius` controls `border-radius` property optimizatons; defaults to `on`'); @@ -50,6 +47,9 @@ commands.on('--help', function () { console.log(' %> # `optimizeFont controls `font` property optimizatons; defaults to `on` '); console.log(' %> # `optimizeFontWeight` controls `font-weight` property optimizatons; defaults to `on`'); console.log(' %> # `optimizeOutline` controls `outline` property optimizatons; defaults to `on`'); + console.log(' %> # `removeNegativePaddings` controls removing negative paddings; defaults to `on`'); + console.log(' %> # `removeQuotes` controls removing quotes when unnecessary; defaults to `on`'); + console.log(' %> # `removeWhitespace` controls removing unused whitespace; defaults to `on`'); console.log(' %> # `replaceMultipleZeros` contols removing redundant zeros; defaults to `on`'); console.log(' %> # `replaceTimeUnits` controls replacing time units with shorter values; defaults to `on'); console.log(' %> # `replaceZeroUnits` controls replacing zero values with units; defaults to `on`'); diff --git a/lib/optimizer/level-1/optimize.js b/lib/optimizer/level-1/optimize.js index c48c58ab..ac9b0752 100644 --- a/lib/optimizer/level-1/optimize.js +++ b/lib/optimizer/level-1/optimize.js @@ -435,7 +435,7 @@ function optimizeBody(properties, context) { property.unused = true; } - if (!levelOptions.keepNegativePaddings && name.indexOf('padding') === 0 && (isNegative(property.value[0]) || isNegative(property.value[1]) || isNegative(property.value[2]) || isNegative(property.value[3]))) { + if (levelOptions.removeNegativePaddings && name.indexOf('padding') === 0 && (isNegative(property.value[0]) || isNegative(property.value[1]) || isNegative(property.value[2]) || isNegative(property.value[3]))) { property.unused = true; } @@ -473,13 +473,13 @@ function optimizeBody(properties, context) { removeUrlQuotes(value) : value; } else if (isQuoted(value)) { - value = levelOptions.keepQuotes ? - value : - removeQuotes(name, value); + value = levelOptions.removeQuotes ? + removeQuotes(name, value) : + value; } else { - value = levelOptions.keepWhitespace ? - value : - optimizeWhitespace(name, value); + value = levelOptions.removeWhitespace ? + optimizeWhitespace(name, value) : + value; value = optimizePrecision(name, value, options.precision); value = optimizePixelLengths(name, value, options.compatibility); value = levelOptions.replaceTimeUnits ? diff --git a/lib/options/optimization-level.js b/lib/options/optimization-level.js index 9c042879..0ed1c700 100644 --- a/lib/options/optimization-level.js +++ b/lib/options/optimization-level.js @@ -12,9 +12,6 @@ var DEFAULTS = {}; DEFAULTS[OptimizationLevel.Zero] = {}; DEFAULTS[OptimizationLevel.One] = { cleanupCharsets: true, - keepNegativePaddings: false, - keepQuotes: false, - keepWhitespace: false, normalizeUrls: true, optimizeBackground: true, optimizeBorderRadius: true, @@ -22,6 +19,9 @@ DEFAULTS[OptimizationLevel.One] = { optimizeFont: true, optimizeFontWeight: true, optimizeOutline: true, + removeNegativePaddings: true, + removeQuotes: true, + removeWhitespace: true, replaceMultipleZeros: true, replaceTimeUnits: true, replaceZeroUnits: true, diff --git a/test/optimizer/level-1/optimize-test.js b/test/optimizer/level-1/optimize-test.js index cda11b24..f2a1fa8f 100644 --- a/test/optimizer/level-1/optimize-test.js +++ b/test/optimizer/level-1/optimize-test.js @@ -1031,30 +1031,6 @@ vows.describe('level 1 optimizations') ] }, { level: { 1: { cleanupCharsets: false } } }) ) - .addBatch( - optimizerContext('negative padding optimizations off', { - 'stays as it is': [ - '.block{padding:-2px}', - '.block{padding:-2px}' - ] - }, { level: { 1: { keepNegativePaddings: true } } }) - ) - .addBatch( - optimizerContext('quotes optimizations off', { - 'stays as it is': [ - '.block{font:"Arial"}', - '.block{font:"Arial"}' - ] - }, { level: { 1: { keepQuotes: true } } }) - ) - .addBatch( - optimizerContext('whitespace optimizations off', { - 'stays as it is': [ - '.block{clip:rect(0, 0, 0, 0)}', - '.block{clip:rect(0, 0, 0, 0)}' - ] - }, { level: { 1: { keepWhitespace: true } } }) - ) .addBatch( optimizerContext('URL normalization off', { 'stays as it is': [ @@ -1115,6 +1091,30 @@ vows.describe('level 1 optimizations') ] }, { level: { 1: { optimizeOutline: false } } }) ) + .addBatch( + optimizerContext('negative padding optimizations off', { + 'stays as it is': [ + '.block{padding:-2px}', + '.block{padding:-2px}' + ] + }, { level: { 1: { removeNegativePaddings: false } } }) + ) + .addBatch( + optimizerContext('quotes optimizations off', { + 'stays as it is': [ + '.block{font:"Arial"}', + '.block{font:"Arial"}' + ] + }, { level: { 1: { removeQuotes: false } } }) + ) + .addBatch( + optimizerContext('whitespace optimizations off', { + 'stays as it is': [ + '.block{clip:rect(0, 0, 0, 0)}', + '.block{clip:rect(0, 0, 0, 0)}' + ] + }, { level: { 1: { removeWhitespace: false } } }) + ) .addBatch( optimizerContext('replace multiple zeros optimization off', { 'stays as it is': [ diff --git a/test/options/optimization-level-test.js b/test/options/optimization-level-test.js index bed2f878..6c5fc804 100644 --- a/test/options/optimization-level-test.js +++ b/test/options/optimization-level-test.js @@ -20,9 +20,6 @@ vows.describe(optimizationLevelFrom) 'has level 1 options': function (levelOptions) { assert.deepEqual(levelOptions['1'], { cleanupCharsets: true, - keepNegativePaddings: false, - keepQuotes: false, - keepWhitespace: false, normalizeUrls: true, optimizeBackground: true, optimizeBorderRadius: true, @@ -30,6 +27,9 @@ vows.describe(optimizationLevelFrom) optimizeFont: true, optimizeFontWeight: true, optimizeOutline: true, + removeNegativePaddings: true, + removeQuotes: true, + removeWhitespace: true, replaceMultipleZeros: true, replaceTimeUnits: true, replaceZeroUnits: true, @@ -65,9 +65,6 @@ vows.describe(optimizationLevelFrom) 'has level 1 options': function (levelOptions) { assert.deepEqual(levelOptions['1'], { cleanupCharsets: true, - keepNegativePaddings: false, - keepQuotes: false, - keepWhitespace: false, normalizeUrls: true, optimizeBackground: true, optimizeBorderRadius: true, @@ -75,6 +72,9 @@ vows.describe(optimizationLevelFrom) optimizeFont: true, optimizeFontWeight: true, optimizeOutline: true, + removeNegativePaddings: true, + removeQuotes: true, + removeWhitespace: true, replaceMultipleZeros: true, replaceTimeUnits: true, replaceZeroUnits: true, @@ -99,9 +99,6 @@ vows.describe(optimizationLevelFrom) 'has level 1 options': function (levelOptions) { assert.deepEqual(levelOptions['1'], { cleanupCharsets: true, - keepNegativePaddings: false, - keepQuotes: false, - keepWhitespace: false, normalizeUrls: true, optimizeBackground: true, optimizeBorderRadius: true, @@ -109,6 +106,9 @@ vows.describe(optimizationLevelFrom) optimizeFont: true, optimizeFontWeight: true, optimizeOutline: true, + removeNegativePaddings: true, + removeQuotes: true, + removeWhitespace: true, replaceMultipleZeros: true, replaceTimeUnits: true, replaceZeroUnits: true, @@ -158,9 +158,6 @@ vows.describe(optimizationLevelFrom) 'has level 1 options': function (levelOptions) { assert.deepEqual(levelOptions['1'], { cleanupCharsets: true, - keepNegativePaddings: false, - keepQuotes: false, - keepWhitespace: false, normalizeUrls: true, optimizeBackground: true, optimizeBorderRadius: true, @@ -168,6 +165,9 @@ vows.describe(optimizationLevelFrom) optimizeFont: true, optimizeFontWeight: true, optimizeOutline: true, + removeNegativePaddings: true, + removeQuotes: true, + removeWhitespace: true, replaceMultipleZeros: true, replaceTimeUnits: true, replaceZeroUnits: true, @@ -206,9 +206,6 @@ vows.describe(optimizationLevelFrom) 'has level 1 options': function (levelOptions) { assert.deepEqual(levelOptions['1'], { cleanupCharsets: true, - keepNegativePaddings: false, - keepQuotes: false, - keepWhitespace: false, normalizeUrls: true, optimizeBackground: true, optimizeBorderRadius: true, @@ -216,6 +213,9 @@ vows.describe(optimizationLevelFrom) optimizeFont: true, optimizeFontWeight: true, optimizeOutline: true, + removeNegativePaddings: true, + removeQuotes: true, + removeWhitespace: true, replaceMultipleZeros: true, replaceTimeUnits: true, replaceZeroUnits: true, @@ -254,9 +254,6 @@ vows.describe(optimizationLevelFrom) 'has level 1 options': function (levelOptions) { assert.deepEqual(levelOptions['1'], { cleanupCharsets: true, - keepNegativePaddings: false, - keepQuotes: false, - keepWhitespace: false, normalizeUrls: true, optimizeBackground: true, optimizeBorderRadius: true, @@ -264,6 +261,9 @@ vows.describe(optimizationLevelFrom) optimizeFont: true, optimizeFontWeight: true, optimizeOutline: true, + removeNegativePaddings: true, + removeQuotes: true, + removeWhitespace: true, replaceMultipleZeros: true, replaceTimeUnits: true, replaceZeroUnits: true, @@ -302,9 +302,6 @@ vows.describe(optimizationLevelFrom) 'has level 1 options': function (levelOptions) { assert.deepEqual(levelOptions['1'], { cleanupCharsets: true, - keepNegativePaddings: false, - keepQuotes: false, - keepWhitespace: false, normalizeUrls: true, optimizeBackground: true, optimizeBorderRadius: true, @@ -312,6 +309,9 @@ vows.describe(optimizationLevelFrom) optimizeFont: true, optimizeFontWeight: true, optimizeOutline: true, + removeNegativePaddings: true, + removeQuotes: true, + removeWhitespace: true, replaceMultipleZeros: true, replaceTimeUnits: true, replaceZeroUnits: true, @@ -336,9 +336,6 @@ vows.describe(optimizationLevelFrom) 'has level 1 options': function (levelOptions) { assert.deepEqual(levelOptions['1'], { cleanupCharsets: true, - keepNegativePaddings: false, - keepQuotes: false, - keepWhitespace: false, normalizeUrls: true, optimizeBackground: true, optimizeBorderRadius: true, @@ -346,6 +343,9 @@ vows.describe(optimizationLevelFrom) optimizeFont: true, optimizeFontWeight: true, optimizeOutline: true, + removeNegativePaddings: true, + removeQuotes: true, + removeWhitespace: true, replaceMultipleZeros: true, replaceTimeUnits: true, replaceZeroUnits: true, @@ -384,9 +384,6 @@ vows.describe(optimizationLevelFrom) 'has level 1 options': function (levelOptions) { assert.deepEqual(levelOptions['1'], { cleanupCharsets: true, - keepNegativePaddings: false, - keepQuotes: false, - keepWhitespace: false, normalizeUrls: true, optimizeBackground: true, optimizeBorderRadius: true, @@ -394,6 +391,9 @@ vows.describe(optimizationLevelFrom) optimizeFont: true, optimizeFontWeight: true, optimizeOutline: true, + removeNegativePaddings: true, + removeQuotes: true, + removeWhitespace: true, replaceMultipleZeros: true, replaceTimeUnits: true, replaceZeroUnits: true, @@ -432,9 +432,6 @@ vows.describe(optimizationLevelFrom) 'has level 1 options': function (levelOptions) { assert.deepEqual(levelOptions['1'], { cleanupCharsets: true, - keepNegativePaddings: false, - keepQuotes: false, - keepWhitespace: false, normalizeUrls: true, optimizeBackground: true, optimizeBorderRadius: true, @@ -442,6 +439,9 @@ vows.describe(optimizationLevelFrom) optimizeFont: true, optimizeFontWeight: true, optimizeOutline: true, + removeNegativePaddings: true, + removeQuotes: true, + removeWhitespace: true, replaceMultipleZeros: true, replaceTimeUnits: true, replaceZeroUnits: true, @@ -480,9 +480,6 @@ vows.describe(optimizationLevelFrom) 'has level 1 options': function (levelOptions) { assert.deepEqual(levelOptions['1'], { cleanupCharsets: true, - keepNegativePaddings: false, - keepQuotes: false, - keepWhitespace: false, normalizeUrls: true, optimizeBackground: true, optimizeBorderRadius: true, @@ -490,6 +487,9 @@ vows.describe(optimizationLevelFrom) optimizeFont: true, optimizeFontWeight: true, optimizeOutline: true, + removeNegativePaddings: true, + removeQuotes: true, + removeWhitespace: true, replaceMultipleZeros: true, replaceTimeUnits: true, replaceZeroUnits: true, @@ -528,9 +528,6 @@ vows.describe(optimizationLevelFrom) 'has level 1 options': function (levelOptions) { assert.deepEqual(levelOptions['1'], { cleanupCharsets: true, - keepNegativePaddings: false, - keepQuotes: false, - keepWhitespace: false, normalizeUrls: true, optimizeBackground: true, optimizeBorderRadius: true, @@ -538,6 +535,9 @@ vows.describe(optimizationLevelFrom) optimizeFont: true, optimizeFontWeight: true, optimizeOutline: true, + removeNegativePaddings: true, + removeQuotes: true, + removeWhitespace: true, replaceMultipleZeros: true, replaceTimeUnits: true, replaceZeroUnits: true, @@ -562,9 +562,6 @@ vows.describe(optimizationLevelFrom) 'has level 1 options': function (levelOptions) { assert.deepEqual(levelOptions['1'], { cleanupCharsets: true, - keepNegativePaddings: false, - keepQuotes: false, - keepWhitespace: false, normalizeUrls: true, optimizeBackground: true, optimizeBorderRadius: true, @@ -572,6 +569,9 @@ vows.describe(optimizationLevelFrom) optimizeFont: true, optimizeFontWeight: true, optimizeOutline: true, + removeNegativePaddings: true, + removeQuotes: true, + removeWhitespace: true, replaceMultipleZeros: true, replaceTimeUnits: true, replaceZeroUnits: true, @@ -613,9 +613,6 @@ vows.describe(optimizationLevelFrom) 'has level 1 options': function (levelOptions) { assert.deepEqual(levelOptions['1'], { cleanupCharsets: true, - keepNegativePaddings: false, - keepQuotes: false, - keepWhitespace: false, normalizeUrls: true, optimizeBackground: true, optimizeBorderRadius: true, @@ -623,6 +620,9 @@ vows.describe(optimizationLevelFrom) optimizeFont: true, optimizeFontWeight: true, optimizeOutline: true, + removeNegativePaddings: true, + removeQuotes: true, + removeWhitespace: true, replaceMultipleZeros: true, replaceTimeUnits: true, replaceZeroUnits: true, -- 2.34.1