Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit c9cc0a3

Browse files
committed
More stricter rules for linting
1 parent 2814b9f commit c9cc0a3

File tree

14 files changed

+518
-162
lines changed

14 files changed

+518
-162
lines changed

.eslintrc

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,41 @@ env:
99

1010
# 0: off, 1: warning, 2: error
1111
rules:
12+
# max 80 chars per line
13+
max-len: [2, 80, 4]
14+
15+
# 2 spaces indentation
16+
indent: [2, 2]
17+
18+
# double quote to match json
19+
quotes: [2, "double"]
20+
1221
# semicolons are useless
1322
semi: [2, "never"]
1423

15-
quotes: [2, "double"]
24+
# consistent whitespace after keywords
25+
space-after-keywords: [2, "always"]
1626

17-
# 2 spaces indentation
18-
indent: [2, 2]
27+
# consistent whitespace before blocks
28+
space-before-blocks: [2, "always"]
29+
30+
# consistent whitespace before function paren
31+
space-before-function-paren: [2, "never"]
32+
33+
# consistent whitespace in brackets
34+
space-in-brackets: [2, "never"]
35+
36+
# consistent whitespace in parens
37+
space-in-parens: [2, "never"]
38+
39+
# consistent whitespace in single line comments
40+
spaced-line-comment: [2, "always"]
41+
42+
# single empty lines only
43+
no-multiple-empty-lines: [2, {"max": 1}]
44+
45+
# one brace per line
46+
"brace-style": [2, "stroustrup"]
1947

2048
# trailing coma are cool for diff
2149
comma-dangle: [2, "always-multiline"]

bin/cssnext.js

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
var fs = require("fs")
44
var path = require("path")
55

6-
// until this land in a stable version of node,
7-
// https://github.com/joyent/node/commit/20176a98416353d4596900793f739d5ebf4f0ee1
6+
// until this land in a stable version of node (for a while)
7+
// https://github.com/joyent/node/commit/20176a
88
// we will this instead of process.exit()
99
var exit = require("exit")
1010

11-
var colors = require("colors")
11+
var color = require("chalk")
1212
var program = require("commander")
1313

1414
var cssnext = require("..")
@@ -36,6 +36,7 @@ Object.keys(cssnext.features).forEach(function(feature) {
3636
program.option(flag, desc)
3737
})
3838

39+
/* eslint-disable no-multiple-empty-lines */
3940
program.on("--help", function() {
4041
console.log(function() {/*
4142
Examples:
@@ -53,6 +54,7 @@ program.on("--help", function() {
5354
*/
5455
}.toString().split("\n").slice(1, -2).join("\n"))
5556
})
57+
/* eslint-enable no-multiple-empty-lines */
5658

5759
program.parse(process.argv)
5860

@@ -66,19 +68,31 @@ Object.keys(cssnext.features).forEach(function(feature) {
6668
config.features[feature] = false
6769
}
6870
})
69-
if ("browsers" in program) { config.browsers = program.browsers }
70-
if ("import" in program) { config.import = program.import }
71-
if ("url" in program) { config.url = program.url }
72-
if ("sourcemap" in program) { config.sourcemap = program.sourcemap }
73-
if ("compress" in program) { config.compress = program.compress }
74-
if ("watch" in program) { config.watch = program.watch }
71+
if ("browsers" in program) {
72+
config.browsers = program.browsers
73+
}
74+
if ("import" in program) {
75+
config.import = program.import
76+
}
77+
if ("url" in program) {
78+
config.url = program.url
79+
}
80+
if ("sourcemap" in program) {
81+
config.sourcemap = program.sourcemap
82+
}
83+
if ("compress" in program) {
84+
config.compress = program.compress
85+
}
86+
if ("watch" in program) {
87+
config.watch = program.watch
88+
}
7589

7690
var input = program.args[0] ? path.resolve(program.args[0]) : null
7791
var output = program.args[1] ? path.resolve(program.args[1]) : null
7892
var verbose = program.verbose
7993

8094
if (input && !fs.existsSync(input)) {
81-
console.error(colors.red("Unable to read file"), input)
95+
console.error(color.red("Unable to read file"), input)
8296
exit(1)
8397
}
8498

@@ -87,7 +101,9 @@ config.from = input
87101
var watcher
88102
if (config.watch) {
89103
if (!input || !output) {
90-
console.error(colors.red("--watch option need both <input> & <output> files to work"))
104+
console.error(
105+
color.red("--watch option need both <input> & <output> files to work")
106+
)
91107
exit(3)
92108
}
93109

@@ -148,20 +164,20 @@ function transform() {
148164

149165
require("write-file-stdout")(output, css)
150166
if (verbose && output) {
151-
log(colors.cyan("Output written"), output)
167+
log(color.cyan("Output written"), output)
152168
}
153169
}
154170
catch (e) {
155171
console.error()
156-
console.error(colors.bold("cssnext encounters an error:"))
172+
console.error(color.bold("cssnext encounters an error:"))
157173
console.error()
158-
console.error(colors.red(e.message))
174+
console.error(color.red(e.message))
159175
if (e.stack) {
160176
console.error(e.stack.split("\n").slice(1).join("\n").grey)
161177
console.error()
162178
}
163179
console.error("If this error looks like a bug, please report it here:")
164-
console.error(colors.grey("❯ ") + pkg.bugs.url.cyan)
180+
console.error(color.grey("❯ ") + pkg.bugs.url.cyan)
165181
console.error()
166182
if (!config.watch) {
167183
exit(2)
@@ -175,7 +191,7 @@ transform()
175191
if (watcher) {
176192
watcher.on("ready", function() {
177193
if (verbose) {
178-
log(colors.cyan("Watching"), input)
194+
log(color.cyan("Watching"), input)
179195
}
180196

181197
watcher.on("change", transform)
@@ -185,10 +201,11 @@ if (watcher) {
185201
/**
186202
* log content prefixed by time
187203
*
188-
* @return {String} output all given parameters prefixed by the current locale time
204+
* @return {String} output all given parameters prefixed by the current locale
205+
* time
189206
*/
190207
function log() {
191208
var args = [].slice.call(arguments)
192-
args.unshift("[" + colors.grey(new Date().toLocaleTimeString()) + "]")
209+
args.unshift("[" + color.grey(new Date().toLocaleTimeString()) + "]")
193210
console.log.apply(console.log, args)
194211
}

index.js

Lines changed: 96 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ var caniuse = require("caniuse-api")
1111
// null == always enable (& no caniuse data)
1212
var caniuseFeaturesMap = {
1313
customProperties: ["css-variables"],
14-
// calc: null, // calc() transformation only make sense with transformed custom properties, don't you think ?
14+
// calc() transformation only make sense with transformed custom properties,
15+
// don't you think ?
16+
// calc: null,
1517
// @todo open PR on caniuse repo https://github.com/Fyrd/caniuse
1618
// customMedia: [null],
1719
// mediaQueriesRange: [null],
@@ -22,44 +24,75 @@ var caniuseFeaturesMap = {
2224
// colorHexAlpha: [null],
2325
// colorFunction:[null],
2426
// fontVariant: [null],
25-
// filter: [null], // @todo can be done using a callback, this is only used for Firefox < 35
27+
// @todo can be done using a callback, this is only used for Firefox < 35
28+
// filter: [null],
2629
rem: ["rem"],
2730
pseudoElements: ["css-gencontent"],
2831
// pseudoClassMatches: [null],
2932
// pseudoClassNot: [null],
3033
colorRgba: ["css3-colors"],
31-
// autoprefixer: [null] // will always be null since autoprefixer does the same game as we do
34+
// will always be null since autoprefixer does the same game as we do
35+
// autoprefixer: [null]
3236
}
3337

3438
var libraryFeatures = {
3539
// Reminder: order is important
36-
customProperties: function(options) { return require("postcss-custom-properties")(options) },
37-
calc: function(options) { return require("postcss-calc")(options)},
38-
customMedia: function(options) { return require("postcss-custom-media")(options)},
39-
mediaQueriesRange: function(options) { return require("postcss-media-minmax")(options)},
40-
customSelectors: function(options) { return require("postcss-custom-selectors")(options)},
41-
colorRebeccapurple: function(options) { return require("postcss-color-rebeccapurple")(options)},
42-
colorHwb: function(options) { return require("postcss-color-hwb")(options)},
43-
colorGray: function(options) { return require("postcss-color-gray")(options)},
44-
colorHexAlpha: function(options) { return require("postcss-color-hex-alpha")(options)},
45-
colorFunction: function(options) { return require("postcss-color-function")(options)},
46-
fontVariant: function(options) { return require("postcss-font-variant")(options)},
47-
filter: function(options) { return require("pleeease-filters")(options)},
48-
rem: function(options) { return require("pixrem")(options)},
49-
pseudoElements: function(options) { return require("postcss-pseudoelements")(options)},
50-
pseudoClassMatches: function(options) { return require("postcss-selector-matches")(options)},
51-
pseudoClassNot: function(options) { return require("postcss-selector-not")(options)},
52-
colorRgba: function(options) { return require("postcss-color-rgba-fallback")(options)},
53-
autoprefixer: function(options) { return require("autoprefixer-core")(options).postcss},
40+
customProperties: function(options) {
41+
return require("postcss-custom-properties")(options)
42+
},
43+
calc: function(options) {
44+
return require("postcss-calc")(options)
45+
},
46+
customMedia: function(options) {
47+
return require("postcss-custom-media")(options)
48+
},
49+
mediaQueriesRange: function(options) {
50+
return require("postcss-media-minmax")(options)
51+
},
52+
customSelectors: function(options) {
53+
return require("postcss-custom-selectors")(options)
54+
},
55+
colorRebeccapurple: function(options) {
56+
return require("postcss-color-rebeccapurple")(options)
57+
},
58+
colorHwb: function(options) {
59+
return require("postcss-color-hwb")(options)
60+
},
61+
colorGray: function(options) {
62+
return require("postcss-color-gray")(options)
63+
},
64+
colorHexAlpha: function(options) {
65+
return require("postcss-color-hex-alpha")(options)
66+
},
67+
colorFunction: function(options) {
68+
return require("postcss-color-function")(options)
69+
},
70+
fontVariant: function(options) {
71+
return require("postcss-font-variant")(options)
72+
},
73+
filter: function(options) {
74+
return require("pleeease-filters")(options)
75+
},
76+
rem: function(options) {
77+
return require("pixrem")(options)
78+
},
79+
pseudoElements: function(options) {
80+
return require("postcss-pseudoelements")(options)
81+
},
82+
pseudoClassMatches: function(options) {
83+
return require("postcss-selector-matches")(options)
84+
},
85+
pseudoClassNot: function(options) {
86+
return require("postcss-selector-not")(options)
87+
},
88+
colorRgba: function(options) {
89+
return require("postcss-color-rgba-fallback")(options)
90+
},
91+
autoprefixer: function(options) {
92+
return require("autoprefixer-core")(options).postcss
93+
},
5494
}
5595

56-
/**
57-
* Expose cssnext
58-
*
59-
* @type {Function}
60-
*/
61-
module.exports = cssnext
62-
6396
/**
6497
* Process a CSS `string`
6598
*
@@ -83,7 +116,8 @@ function cssnext(string, options) {
83116

84117
var features = options.features || {}
85118

86-
// options.browsers is deliberately undefined by defaut to inherit browserslist default behavior
119+
// options.browsers is deliberately undefined by defaut to inherit
120+
// browserslist default behavior
87121

88122
// default sourcemap
89123
// if `map` option is passed, `sourcemap` option is ignored
@@ -93,9 +127,13 @@ function cssnext(string, options) {
93127
// propagate browsers option to autoprefixer
94128
if (features.autoprefixer !== false) {
95129
features.autoprefixer = features.autoprefixer || {}
96-
features.autoprefixer.browsers = features.autoprefixer.browsers || options.browsers
130+
features.autoprefixer.browsers = features.autoprefixer.browsers ||
131+
options.browsers
132+
97133
// autoprefixer doesn't like an "undefined" value. Related to coffee ?
98-
if (features.autoprefixer.browsers === undefined) {delete features.autoprefixer.browsers}
134+
if (features.autoprefixer.browsers === undefined) {
135+
delete features.autoprefixer.browsers
136+
}
99137
}
100138

101139
var postcssInstance = postcss()
@@ -105,18 +143,29 @@ function cssnext(string, options) {
105143
if (fs && fs.readFile) {
106144
// @import
107145
if (options.import !== false) {
108-
postcssInstance.use(require("postcss-import")(typeof options.import === "object" ? options.import : undefined))
146+
postcssInstance.use(require("postcss-import")(
147+
typeof options.import === "object"
148+
? options.import
149+
: undefined
150+
)
151+
)
109152
}
110153

111154
// url() adjustements
112155
if (options.url !== false) {
113-
postcssInstance.use(require("postcss-url")(typeof options.url === "object" ? options.url : undefined))
156+
postcssInstance.use(require("postcss-url")(
157+
typeof options.url === "object"
158+
? options.url
159+
: undefined
160+
)
161+
)
114162
}
115163
}
116164

117165
// features
118166
Object.keys(cssnext.features).forEach(function(key) {
119-
// feature is auto enabled if: not disable && (enabled || no data yet || !supported yet)
167+
// feature is auto enabled if: not disable && (enabled || no data yet ||
168+
// !supported yet)
120169
if (
121170
// feature is not disabled
122171
features[key] !== false &&
@@ -135,7 +184,12 @@ function cssnext(string, options) {
135184
)
136185
)
137186
) {
138-
postcssInstance.use(cssnext.features[key](typeof features[key] === "object" ? features[key] : undefined))
187+
postcssInstance.use(cssnext.features[key](
188+
typeof features[key] === "object"
189+
? features[key]
190+
: undefined
191+
)
192+
)
139193
}
140194
})
141195

@@ -178,3 +232,10 @@ function cssnext(string, options) {
178232
* @type {Object}
179233
*/
180234
cssnext.features = libraryFeatures
235+
236+
/**
237+
* Expose cssnext
238+
*
239+
* @type {Function}
240+
*/
241+
module.exports = cssnext

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
},
6363
"devDependencies": {
6464
"browserify": "^8.1.1",
65-
"eslint": "^0.20.0",
65+
"eslint": "^0.21.2",
6666
"microtime": "^1.2.0",
6767
"tape": "^3.0.0"
6868
},

0 commit comments

Comments
 (0)