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

Commit c6f6834

Browse files
Adding in ESLint and fixing basic errors to match #104
1 parent f8dabb5 commit c6f6834

13 files changed

+154
-125
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

.eslintrc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
# babel support more syntax stuff than eslint for now
3+
#parser: babel-eslint
4+
5+
ecmaFeatures:
6+
modules: true
7+
8+
env:
9+
es6: true
10+
browser: true
11+
node: true
12+
13+
# 0: off, 1: warning, 2: error
14+
rules:
15+
# semicolons are useless
16+
semi: [2, "never"]
17+
18+
quotes: [2, "double"]
19+
20+
# 2 spaces indentation
21+
indent: [2, 2]
22+
23+
# trailing coma are cool for diff
24+
comma-dangle: [2, "always-multiline"]
25+
26+
# enforce comma at eol (never before)
27+
comma-style: [2, "last"]

index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Modules dependencies
33
*/
4-
var Postcss = require("postcss")
4+
var postcss = require("postcss")
55
var assign = require("object-assign")
66
var caniuse = require("caniuse-api")
77

@@ -31,7 +31,7 @@ var caniuseFeaturesMap = {
3131
// autoprefixer: [null] // will always be null since autoprefixer does the same game as we do
3232
}
3333

34-
var features = {
34+
var libraryFeatures = {
3535
// Reminder: order is important
3636
customProperties: function(options) { return require("postcss-custom-properties")(options) },
3737
calc: function(options) { return require("postcss-calc")(options)},
@@ -50,7 +50,7 @@ var features = {
5050
pseudoClassMatches: function(options) { return require("postcss-selector-matches")(options)},
5151
pseudoClassNot: function(options) { return require("postcss-selector-not")(options)},
5252
colorRgba: function(options) { return require("postcss-color-rgba-fallback")(options)},
53-
autoprefixer: function(options) { return require("autoprefixer-core")(options).postcss}
53+
autoprefixer: function(options) { return require("autoprefixer-core")(options).postcss},
5454
}
5555

5656
/**
@@ -98,19 +98,19 @@ function cssnext(string, options) {
9898
if (features.autoprefixer.browsers === undefined) {delete features.autoprefixer.browsers}
9999
}
100100

101-
var postcss = Postcss()
101+
var postcssInstance = postcss()
102102

103103
// only enable import & url if fs module is available
104104
var fs = require("fs")
105105
if (fs && fs.readFile) {
106106
// @import
107107
if (options.import !== false) {
108-
postcss.use(require("postcss-import")(typeof options.import === "object" ? options.import : undefined))
108+
postcssInstance.use(require("postcss-import")(typeof options.import === "object" ? options.import : undefined))
109109
}
110110

111111
// url() adjustements
112112
if (options.url !== false) {
113-
postcss.use(require("postcss-url")(typeof options.url === "object" ? options.url : undefined))
113+
postcssInstance.use(require("postcss-url")(typeof options.url === "object" ? options.url : undefined))
114114
}
115115
}
116116

@@ -135,19 +135,19 @@ function cssnext(string, options) {
135135
)
136136
)
137137
) {
138-
postcss.use(cssnext.features[key](typeof features[key] === "object" ? features[key] : undefined))
138+
postcssInstance.use(cssnext.features[key](typeof features[key] === "object" ? features[key] : undefined))
139139
}
140140
})
141141

142142
// minification
143143
if (options.compress) {
144144
var csswring = require("csswring")
145-
postcss.use(typeof options.compress === "object" ? csswring(options.compress) : csswring)
145+
postcssInstance.use(typeof options.compress === "object" ? csswring(options.compress) : csswring)
146146
}
147147

148148
// classic API if string is passed
149149
if (typeof string === "string") {
150-
var result = postcss.process(string, options)
150+
var result = postcssInstance.process(string, options)
151151

152152
// default behavior, cssnext returns a css string if no or inline sourcemap
153153
if (options.map === null || (options.map === true || options.map.inline)) {
@@ -159,7 +159,7 @@ function cssnext(string, options) {
159159
}
160160
// or return the postcss instance that can be consumed as a postcss plugin
161161
else {
162-
return postcss
162+
return postcssInstance
163163
}
164164
}
165165

@@ -168,4 +168,4 @@ function cssnext(string, options) {
168168
*
169169
* @type {Object}
170170
*/
171-
cssnext.features = features
171+
cssnext.features = libraryFeatures

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
},
6363
"devDependencies": {
6464
"browserify": "^8.1.1",
65+
"eslint": "^0.20.0",
6566
"jscs": "^1.6.2",
6667
"jshint": "^2.5.6",
6768
"microtime": "^1.2.0",
@@ -71,7 +72,8 @@
7172
"standalone": "browserify --standalone cssnext index.js -o dist/cssnext.js",
7273
"jscs": "jscs .",
7374
"jshint": "jshint . --exclude-path .gitignore",
74-
"pretest": "npm run jscs && npm run jshint && npm run standalone",
75+
"eslint": "eslint -f tap .",
76+
"pretest": "npm run eslint && npm run jscs && npm run jshint && npm run standalone",
7577
"test": "tape test/*.js"
7678
},
7779
"bin": {

test/cases.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ test("use case: use plugin options", function(t) {
2929
{
3030
features: {
3131
customProperties: {
32-
preserve: true
33-
}
34-
}
32+
preserve: true,
33+
},
34+
},
3535
}
3636
),
3737
utils.readFixture("cases/plugin-options.expected"),

test/cli.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,40 @@ test("cli", function(t) {
2525
t.equal(res, output, "should read from a file and write to a file")
2626
utils.remove("cli.output--io")
2727
})
28-
planned+=1
28+
planned += 1
2929

3030
exec(cssnextBin + " test/fixtures/cli.css", function(err, stdout) {
3131
if (err) { throw err }
3232
t.equal(stdout, output, "should read from a file and write to stdout")
3333
})
34-
planned+=1
34+
planned += 1
3535

3636
var childProcess = exec(cssnextBin, function(err, stdout) {
3737
if (err) { throw err }
3838
t.equal(stdout, output, "should read from stdin and write to stdout")
3939
})
4040
childProcess.stdin.write(new Buffer(input))
4141
childProcess.stdin.end()
42-
planned+=1
42+
planned += 1
4343

4444
exec(cssnextBin + " test/fixtures/cli.dont-exist.css", function(err, stdout, stderr) {
4545
t.ok(err && err.code === 1, "should return an error when input file is unreadable")
4646
t.ok(utils.contains(stderr, "Unable to read file"), "should show that the input file is not found")
4747
})
48-
planned+=2
48+
planned += 2
4949

5050
exec(cssnextBin + " test/fixtures/cli.error.css", function(err, stdout, stderr) {
5151
t.ok(err && err.code === 2, "should throw an error")
5252
t.ok(utils.contains(stderr, "encounters an error"), "should output a readable error")
5353
t.ok(utils.contains(stderr, "If this error looks like a bug, please report it here"), "should show the url where to report bugs")
5454
})
55-
planned+=3
55+
planned += 3
5656

5757
exec(cssnextBin + " --config test/fixtures/config.json test/fixtures/config.css", function(err, stdout) {
5858
if (err) { throw err }
5959
t.equal(stdout, utils.readFixture("config.expected"), "should read config file on --config")
6060
})
61-
planned+=1
61+
planned += 1
6262

6363
var noCustomPropInput = ":root{--foo:bar}baz{qux:var(--foo)}"
6464
var childProcessBrowsers = exec(cssnextBin + " --browsers \"Firefox >= 31\"", function(err, stdout) {
@@ -67,64 +67,64 @@ test("cli", function(t) {
6767
})
6868
childProcessBrowsers.stdin.write(new Buffer(noCustomPropInput))
6969
childProcessBrowsers.stdin.end()
70-
planned+=1
70+
planned += 1
7171

7272
exec(cssnextBin + " --verbose test/fixtures/cli.css test/fixtures/cli.output--verbose.css", function(err, stdout) {
7373
if (err) { throw err }
7474
t.ok(utils.contains(stdout, "Output written"), "should log on --verbose")
7575
utils.remove("cli.output--verbose")
7676
})
77-
planned+=1
77+
planned += 1
7878

7979
exec(cssnextBin + " --no-import test/fixtures/import.css", function(err, stdout) {
8080
if (err) { throw err }
8181
t.equal(stdout, utils.readFixture("import"), "should not import on --no-import")
8282
})
83-
planned+=1
83+
planned += 1
8484

8585
exec(cssnextBin + " --no-url test/fixtures/url.css", {cwd: process.cwd()}, function(err, stdout) {
8686
if (err) { throw err }
8787
t.equal(stdout, utils.readFixture("url/dep"), "should not adjust url on --no-url")
8888
})
89-
planned+=1
89+
planned += 1
9090

9191
exec(cssnextBin + " --compress test/fixtures/compress.css", function(err, stdout) {
9292
if (err) { throw err }
9393
t.equal(stdout, utils.readFixture("compress.default.expected").trim(), "should compress on --compress")
9494
})
95-
planned+=1
95+
planned += 1
9696

9797
exec(cssnextBin + " --sourcemap test/fixtures/sourcemap.css", function(err, stdout) {
9898
if (err) { throw err }
9999
t.equal(stdout, utils.readFixture("sourcemap.expected").trim(), "should add sourcemap on --sourcemap")
100100
})
101-
planned+=1
101+
planned += 1
102102

103103
var toSpace = require("to-space-case")
104104
var toSlug = require("to-slug-case")
105105
var features = Object.keys(cssnext.features)
106106
var no = "--no-" + features.map(function(feature) { return toSlug(feature)}).join(" --no-")
107107
features.forEach(function(feature) {
108108
var slug = toSlug(feature)
109-
var output = utils.readFixture("features/" + slug)
109+
var featureOutput = utils.readFixture("features/" + slug)
110110
exec(cssnextBin + " " + no + " test/fixtures/features/" + slug + ".css", function(err, stdout) {
111111
if (err) { throw err }
112-
t.equal(stdout, output, "should not modify input of '" + toSpace(feature) + "' fixture if all features are disabled")
112+
t.equal(stdout, featureOutput, "should not modify input of '" + toSpace(feature) + "' fixture if all features are disabled")
113113
})
114114
})
115-
planned+=features.length
115+
planned += features.length
116116

117117
exec(cssnextBin + " --watch", function(err, stdout, stderr) {
118118
t.ok(err && err.code === 3, "should return an error when <input> or <output> are missing when `--watch` option passed")
119119
t.ok(utils.contains(stderr, "--watch option need"), "should show an explanation when <input> or <output> are missing when `--watch` option passed")
120120
})
121-
planned+=2
121+
planned += 2
122122

123123
exec(cssnextBin + " --watch test/fixtures/cli.css", function(err, stdout, stderr) {
124124
t.ok(err && err.code === 3, "should return an error when <output> is missing when `--watch` option passed")
125125
t.ok(utils.contains(stderr, "--watch option need"), "should show an explanation when <output> is missing when `--watch` option passed")
126126
})
127-
planned+=2
127+
planned += 2
128128

129129
t.plan(planned)
130130
})

0 commit comments

Comments
 (0)