From d70df3545ae21d225fe150cdc57111f628e6b3a4 Mon Sep 17 00:00:00 2001 From: Efremov Alexey Date: Mon, 18 Jan 2016 11:31:28 +0300 Subject: [PATCH] Fix: codestyle --- .jscsrc | 40 ---------------------- gulpfile.js | 4 +-- index.js | 21 ++++++------ package.json | 32 +++++++++--------- test/main.js | 95 ++++++++++++++++++++++++++-------------------------- 5 files changed, 76 insertions(+), 116 deletions(-) delete mode 100644 .jscsrc diff --git a/.jscsrc b/.jscsrc deleted file mode 100644 index db3b162..0000000 --- a/.jscsrc +++ /dev/null @@ -1,40 +0,0 @@ -{ - "excludeFiles": [ - "node_modules/**", - "bower_components/**", - ".vagrant" - ], - "fileExtensions": [ - ".js" - ], - "esnext": true, - "maxErrors": 10, - "preset": "airbnb", - "requireSpacesInFunctionDeclaration": { - "beforeOpeningCurlyBrace": true - }, - "requireSpaceAfterKeywords": [ - "do", - "for", - "if", - "else", - "switch", - "case", - "try", - "catch", - "while", - "return", - "typeof" - ], - "validateQuoteMarks": { "mark": "\"", "escape": true }, - "requireCamelCaseOrUpperCaseIdentifiers": null, - "safeContextKeyword": "self", - "disallowQuotedKeysInObjects": null, - "requireDotNotation": "except_snake_case", - "disallowMultipleVarDecl": null, - "validateIndentation": 2, - "requireSemicolons": true, - "disallowPaddingNewlinesInBlocks": true, - "requirePaddingNewLinesAfterBlocks" : null, - "requireTrailingComma": null -} diff --git a/gulpfile.js b/gulpfile.js index 12822fb..d412bd4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,11 +4,11 @@ var gulp = require("gulp"); var istanbul = require("gulp-istanbul"); var mocha = require("gulp-mocha"); -gulp.task("test", function(cb) { +gulp.task("test", function (cb) { gulp.src(["test/main.js"]) .pipe(istanbul()) // Covering files .pipe(istanbul.hookRequire()) // Force `require` to return covered files - .on("finish", function() { + .on("finish", function () { gulp.src(["test/main.js"]) .pipe(mocha()) .pipe(istanbul.writeReports()) // Creating the reports after tests runned diff --git a/index.js b/index.js index c02e829..8ce7ef7 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ "use strict"; +/* eslint object-shorthand: 0 */ var nodecss = require("node-css"), _ = require("lodash"), libpath = require("path"); @@ -12,7 +13,7 @@ var css = new CSS(); function CSSImage() { } -CSSImage.prototype.css = function(filepath, width, height, root, options) { +CSSImage.prototype.css = function (filepath, width, height, root, options) { var classname = "." + this.name(filepath, options); if (!options) { options = {}; } if (options.retina) { @@ -29,7 +30,7 @@ CSSImage.prototype.css = function(filepath, width, height, root, options) { }, options); }; -CSSImage.prototype.scssVars = function(filepath, _width, _height, options) { +CSSImage.prototype.scssVars = function (filepath, _width, _height, options) { var name = this.name(filepath, options); var squeeze = (options && !!options.squeeze) ? +options.squeeze : 1; var width = Math.floor(_width / squeeze); @@ -42,7 +43,7 @@ CSSImage.prototype.scssVars = function(filepath, _width, _height, options) { "$" + name + "__path: '" + this.normalizePath(filepath, root, retina) + "';\n"; }; -CSSImage.prototype.scssMixin = function(filepath, _width, _height, root, options) { +CSSImage.prototype.scssMixin = function (filepath, _width, _height, root, options) { var name = this.name(filepath, options); if (!options) { options = {}; } var classname = "@mixin " + name + "()"; @@ -57,7 +58,7 @@ CSSImage.prototype.scssMixin = function(filepath, _width, _height, root, options height: height + "px", "background-image": this.url(filepath, root), "background-size": "" + width + "px " + height + "px" - }, {indent: indent}); + }, { indent: indent }); if (isRetina) { var body = css.body({ @@ -65,22 +66,22 @@ CSSImage.prototype.scssMixin = function(filepath, _width, _height, root, options height: height + "px", "background-image": this.url(filepath, root, options.retina), "background-size": "" + width + "px " + height + "px" - }, {indent: indent + indent}); + }, { indent: indent + indent }); scssMixin += indent + "@media " + MEDIA_QUERY + " {\n" + body + indent + "}\n"; } return classname + " {\n" + scssMixin + "}\n"; }; -CSSImage.prototype.scss = function(filepath, width, height, root, options) { +CSSImage.prototype.scss = function (filepath, width, height, root, options) { return this.scssMixin(filepath, width, height, root, options) + this.scssVars(filepath, width, height, options); }; -CSSImage.prototype.url = function(filepath, root, retina) { +CSSImage.prototype.url = function (filepath, root, retina) { return "url(" + this.normalizePath(filepath, root, retina) + ")"; }; -CSSImage.prototype.normalizePath = function(filepath, root, retina) { +CSSImage.prototype.normalizePath = function (filepath, root, retina) { var name = libpath.basename(filepath); var ext = libpath.extname(filepath); if (!!retina) { @@ -92,7 +93,7 @@ CSSImage.prototype.normalizePath = function(filepath, root, retina) { return normalizedPath; }; -CSSImage.prototype.normalizeFolder = function(filepath, root) { +CSSImage.prototype.normalizeFolder = function (filepath, root) { var folder = libpath.dirname(filepath); if (folder[0] === "." && folder[1] !== ".") { folder = folder.slice(1); } if (folder[0] === "/") { folder = folder.slice(1); } @@ -100,7 +101,7 @@ CSSImage.prototype.normalizeFolder = function(filepath, root) { return result.replace(rxReplacePath, "/").replace(rxCleanSpace, ""); }; -CSSImage.prototype.name = function(filepath, options) { +CSSImage.prototype.name = function (filepath, options) { var postfix = options && options.postfix ? options.postfix : ""; if (options && options.squeeze) { postfix += "-s" + options.squeeze; } var prefix = options && (typeof options.prefix !== "undefined") ? options.prefix : "img_"; diff --git a/package.json b/package.json index 05b988b..d7db4f5 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,10 @@ "main": "index.js", "repository": "http://github.com/lexich/css-image", "scripts": { - "test": "npm run eslint && npm run jscs && npm run mocha", + "test": "npm run eslint && npm run mocha", "mocha": "istanbul test _mocha --report html -- test/*.js --reporter spec", - "coveralls": "npm run eslint && npm run jscs && istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", + "coveralls": "npm run eslint && istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", "testgulp": "node_modules/.bin/gulp test", - "jscs": "node_modules/.bin/jscs ./*.js test/*.js", "eslint": "node_modules/.bin/eslint ./*.js test/*.js" }, "keywords": [ @@ -23,22 +22,21 @@ }, "license": "MIT", "dependencies": { - "lodash": "^3.10.0", + "lodash": "3.10.0", "node-css": "0.1.0" }, "devDependencies": { - "babel-eslint": "^4.0.5", - "chai": "^3.0.0", - "coveralls": "^2.11.3", - "eslint": "^1.0.0", - "eslint-config-airbnb": "0.0.7", - "eslint-plugin-react": "^3.1.0", - "gulp": "^3.9.0", - "gulp-istanbul": "^0.10.0", - "gulp-mocha": "^2.1.3", - "istanbul": "^0.3.17", - "jscs": "^2.0.0", - "mocha": "^2.2.5", - "mocha-lcov-reporter": "0.0.2" + "babel-eslint": "4.0.5", + "chai": "3.4.1", + "coveralls": "2.11.6", + "eslint": "1.10.3", + "eslint-config-airbnb": "3.1.0", + "eslint-plugin-react": "3.15.0", + "gulp": "3.9.0", + "gulp-istanbul": "0.10.3", + "gulp-mocha": "2.2.0", + "istanbul": "0.4.2", + "mocha": "2.3.4", + "mocha-lcov-reporter": "1.0.0" } } diff --git a/test/main.js b/test/main.js index 4133ae4..aba759f 100644 --- a/test/main.js +++ b/test/main.js @@ -5,10 +5,10 @@ var cssimage = require("../"); require("chai").should(); -describe("test CSSImage", function() { +describe("test CSSImage", function () { var CSSImage = cssimage.CSSImage; var c = new CSSImage(); - it("test name", function() { + it("test name", function () { c.name("2.png").should.eql("img_2"); c.name("test/2.jpg").should.eql("img_test_2"); c.name("test/2 Two.jpg").should.eql("img_test_2Two"); @@ -17,11 +17,11 @@ describe("test CSSImage", function() { c.name("./images/test/2.gif").should.eql("img_images_test_2"); c.name(".images/test/2.gif").should.eql("img_images_test_2"); c.name("images/test/.2.jpg").should.eql("img_images_test_2"); - c.name("2.png", {postfix: "-2x"}).should.eql("img_2-2x"); - c.name("images/test/2.png", {separator: "@"}).should.eql("img_images@test@2"); - c.name("images/test/2.png", {prefix: "test_"}).should.eql("test_images_test_2"); + c.name("2.png", { postfix: "-2x" }).should.eql("img_2-2x"); + c.name("images/test/2.png", { separator: "@" }).should.eql("img_images@test@2"); + c.name("images/test/2.png", { prefix: "test_" }).should.eql("test_images_test_2"); }); - it("test normalizeFolder", function() { + it("test normalizeFolder", function () { c.normalizeFolder(".").should.eql(""); c.normalizeFolder("test.jpg").should.eql(""); c.normalizeFolder("/test.jpg").should.eql(""); @@ -30,7 +30,7 @@ describe("test CSSImage", function() { c.normalizeFolder("test/test1.jpg").should.eql("test"); c.normalizeFolder("../images/test").should.eql("../images"); }); - it("test normalizeFolder with root", function() { + it("test normalizeFolder with root", function () { c.normalizeFolder(".", "images").should.eql("images"); c.normalizeFolder("test/test.jpg", "images").should.eql("images/test"); c.normalizeFolder("/test.jpg", "images/root").should.eql("images/root"); @@ -39,7 +39,7 @@ describe("test CSSImage", function() { c.normalizeFolder("../images/test.jpg", "root").should.eql("images"); c.normalizeFolder("images/test.jpg", "../root").should.eql("../root/images"); }); - it("test normalizePath", function() { + it("test normalizePath", function () { c.normalizePath(".").should.eql("."); c.normalizePath("test.jpg").should.eql("test.jpg"); c.normalizePath("/test.jpg").should.eql("test.jpg"); @@ -49,19 +49,19 @@ describe("test CSSImage", function() { c.normalizePath("test.jpg", "root", true).should.eql("root/test-50pc.jpg"); c.normalizePath("test.jpg", "root", "-2x").should.eql("root/test-2x.jpg"); }); - it("test normalizePath with root", function() { + it("test normalizePath with root", function () { c.normalizePath(".", "images").should.eql("images"); c.normalizePath("test/test.jpg", "images").should.eql("images/test/test.jpg"); c.normalizePath("/test.jpg", "images/root").should.eql("images/root/test.jpg"); c.normalizePath("./test.jpg", "images").should.eql("images/test.jpg"); c.normalizePath(".test.jpg", "root").should.eql("root/.test.jpg"); }); - it("test url", function() { + it("test url", function () { c.url("test.jpg", "../images").should.eql("url(../images/test.jpg)"); c.url("test.jpg", "../images", true).should.eql("url(../images/test-50pc.jpg)"); c.url("test.jpg", "../images", "-2x").should.eql("url(../images/test-2x.jpg)"); }); - it("test css", function() { + it("test css", function () { var result = ".img_test_images {\n" + " width: 100px;\n" + " height: 110px;\n" + @@ -75,27 +75,28 @@ describe("test CSSImage", function() { " background-image: url(../images/test/images.jpg);\n" + " background-size: 100px 110px;\n" + "}\n"; - c.css("test/images.jpg", 100, 110, "../images", { postfix: "-2x"}).should.eql(result); + c.css("test/images.jpg", 100, 110, "../images", { postfix: "-2x" }).should.eql(result); }); - it("test css with separator", function() { + it("test css with separator", function () { var result = ".img-test-images {\n" + " width: 100px;\n" + " height: 110px;\n" + " background-image: url(../images/test/images.jpg);\n" + " background-size: 100px 110px;\n" + "}\n"; - c.css("test/images.jpg", 100, 110, "../images", {separator: "-", prefix: "img-"}).should.eql(result); + c.css("test/images.jpg", 100, 110, "../images", { separator: "-", prefix: "img-" }) + .should.eql(result); }); - it("test css with empty prefix", function() { + it("test css with empty prefix", function () { var result = ".test_images {\n" + " width: 100px;\n" + " height: 110px;\n" + " background-image: url(../images/test/images.jpg);\n" + " background-size: 100px 110px;\n" + "}\n"; - c.css("test/images.jpg", 100, 110, "../images", {prefix: ""}).should.eql(result); + c.css("test/images.jpg", 100, 110, "../images", { prefix: "" }).should.eql(result); }); - it("test css with retina", function() { + it("test css with retina", function () { var result = "@media (min-device-pixel-ratio: 2) and (min-resolution: 192dpi) {\n" + " .img_test_images {\n" + " width: 100px;\n" + @@ -104,18 +105,18 @@ describe("test CSSImage", function() { " background-size: 100px 110px;\n" + " }\n" + "}\n"; - c.css("test/images.jpg", 100, 110, "../images", {retina: true}).should.eql(result); + c.css("test/images.jpg", 100, 110, "../images", { retina: true }).should.eql(result); }); - it("test css with squeeze", function() { + it("test css with squeeze", function () { var result = ".img_test_t-s2 {\n" + " width: 50px;\n" + " height: 55px;\n" + " background-image: url(root/test/t.jpg);\n" + " background-size: 50px 55px;\n" + "}\n"; - c.css("test/t.jpg", 100, 110, "root", {squeeze: 2}).should.eql(result); + c.css("test/t.jpg", 100, 110, "root", { squeeze: 2 }).should.eql(result); }); - it("test scssMixin with retina", function() { + it("test scssMixin with retina", function () { var result = "@mixin img_test_images() {\n" + " width: 100px;\n" + " height: 110px;\n" + @@ -128,9 +129,9 @@ describe("test CSSImage", function() { " background-size: 100px 110px;\n" + " }\n" + "}\n"; - c.scssMixin("test/images.jpg", 100, 110, "../images", {retina: true}).should.eql(result); + c.scssMixin("test/images.jpg", 100, 110, "../images", { retina: true }).should.eql(result); }); - it("test scssMixin", function() { + it("test scssMixin", function () { var result = "@mixin img_test_images() {\n" + " width: 100px;\n" + " height: 110px;\n" + @@ -139,26 +140,26 @@ describe("test CSSImage", function() { "}\n"; c.scssMixin("test/images.jpg", 100, 110, "../images").should.eql(result); }); - it("test scssMixin with squeeze", function() { + it("test scssMixin with squeeze", function () { var result = "@mixin img_test_images-s2() {\n" + " width: 50px;\n" + " height: 55px;\n" + " background-image: url(../images/test/images.jpg);\n" + " background-size: 50px 55px;\n" + "}\n"; - c.scssMixin("test/images.jpg", 100, 110, "../images", {squeeze: 2}).should.eql(result); + c.scssMixin("test/images.jpg", 100, 110, "../images", { squeeze: 2 }).should.eql(result); }); - it("test scssMixin with empty prefix", function() { + it("test scssMixin with empty prefix", function () { var result = "@mixin test_images() {\n" + " width: 100px;\n" + " height: 110px;\n" + " background-image: url(../images/test/images.jpg);\n" + " background-size: 100px 110px;\n" + "}\n"; - c.scssMixin("test/images.jpg", 100, 110, "../images", {prefix: ""}).should.eql(result); + c.scssMixin("test/images.jpg", 100, 110, "../images", { prefix: "" }).should.eql(result); }); - it("test scssVars", function() { + it("test scssVars", function () { var result = "$img_test_images__width: 100px;\n" + "$img_test_images__height: 110px;\n" + "$img_test_images__path: 'test/images.jpg';\n"; @@ -166,17 +167,17 @@ describe("test CSSImage", function() { result = "$img_test_images-2x__width: 100px;\n" + "$img_test_images-2x__height: 110px;\n" + "$img_test_images-2x__path: 'test/images.jpg';\n"; - c.scssVars("test/images.jpg", 100, 110, { postfix: "-2x"}).should.eql(result); + c.scssVars("test/images.jpg", 100, 110, { postfix: "-2x" }).should.eql(result); result = "$img_test_images-s2__width: 50px;\n" + "$img_test_images-s2__height: 55px;\n" + "$img_test_images-s2__path: 'test/images.jpg';\n"; - c.scssVars("test/images.jpg", 100, 110, {squeeze: 2}).should.eql(result); + c.scssVars("test/images.jpg", 100, 110, { squeeze: 2 }).should.eql(result); result = "$test_images__width: 100px;\n" + "$test_images__height: 110px;\n" + "$test_images__path: 'test/images.jpg';\n"; - c.scssVars("test/images.jpg", 100, 110, {prefix: ""}).should.eql(result); + c.scssVars("test/images.jpg", 100, 110, { prefix: "" }).should.eql(result); }); - it("test scss", function() { + it("test scss", function () { var result = "@mixin img_test_images() {\n" + " width: 100px;\n" + " height: 110px;\n" + @@ -196,9 +197,9 @@ describe("test CSSImage", function() { "$img_test_images-2x__width: 100px;\n" + "$img_test_images-2x__height: 110px;\n" + "$img_test_images-2x__path: 'test/images.jpg';\n"; - c.scss("test/images.jpg", 100, 110, "../images", { postfix: "-2x"}).should.eql(result); + c.scss("test/images.jpg", 100, 110, "../images", { postfix: "-2x" }).should.eql(result); }); - it("test scss with retina", function() { + it("test scss with retina", function () { var result = "@mixin img_test_images() {\n" + " width: 100px;\n" + " height: 110px;\n" + @@ -214,9 +215,9 @@ describe("test CSSImage", function() { "$img_test_images__width: 100px;\n" + "$img_test_images__height: 110px;\n" + "$img_test_images__path: 'test/images-50pc.jpg';\n"; - c.scss("test/images.jpg", 100, 110, "../images", {retina: true}).should.eql(result); + c.scss("test/images.jpg", 100, 110, "../images", { retina: true }).should.eql(result); }); - it("test external api all args", function() { + it("test external api all args", function () { var result = "" + ".img_t {\n" + " width: 400px;\n" + @@ -263,7 +264,7 @@ describe("test CSSImage", function() { "$img_t-s2__height: 150px;\n" + "$img_t-s2__path: 'root/t.png';\n"; - cssimage([{ width: 400, height: 300, file: "t.png"}], { + cssimage([{ width: 400, height: 300, file: "t.png" }], { css: true, scss: true, retina: true, @@ -271,7 +272,7 @@ describe("test CSSImage", function() { root: "root" }).should.eql(result); }); - it("test external api scss without retina with default", function() { + it("test external api scss without retina with default", function () { var result = "" + "@mixin img_t() {\n" + " width: 400px;\n" + @@ -283,14 +284,14 @@ describe("test CSSImage", function() { "$img_t__height: 300px;\n" + "$img_t__path: 'root/t.png';\n"; - cssimage([{ width: 400, height: 300, file: "t.png"}], { + cssimage([{ width: 400, height: 300, file: "t.png" }], { css: false, scss: true, retina: false, root: "root" }).should.eql(result); }); - it("test external api css all options", function() { + it("test external api css all options", function () { var result = "" + ".img_t {\n" + " width: 400px;\n" + @@ -312,14 +313,14 @@ describe("test CSSImage", function() { " background-image: url(root/t.png);\n" + " background-size: 200px 150px;\n" + "}\n"; - cssimage([{ width: 400, height: 300, file: "t.png"}], { + cssimage([{ width: 400, height: 300, file: "t.png" }], { css: true, retina: true, squeeze: 2, root: "root" }).should.eql(result); }); - it("test external api css retina only", function() { + it("test external api css retina only", function () { var result = "" + ".img_t {\n" + " width: 400px;\n" + @@ -335,13 +336,13 @@ describe("test CSSImage", function() { " background-size: 400px 300px;\n" + " }\n" + "}\n"; - cssimage([{ width: 400, height: 300, file: "t.png"}], { + cssimage([{ width: 400, height: 300, file: "t.png" }], { css: true, retina: true, root: "root" }).should.eql(result); }); - it("test external api css squeeze only", function() { + it("test external api css squeeze only", function () { var result = "" + ".img_t {\n" + " width: 400px;\n" + @@ -355,13 +356,13 @@ describe("test CSSImage", function() { " background-image: url(root/t.png);\n" + " background-size: 200px 150px;\n" + "}\n"; - cssimage([{ width: 400, height: 300, file: "t.png"}], { + cssimage([{ width: 400, height: 300, file: "t.png" }], { css: true, squeeze: 2, root: "root" }).should.eql(result); }); - it("test external api scss all options", function() { + it("test external api scss all options", function () { var result = "" + "@mixin img_t() {\n" + " width: 400px;\n" + @@ -388,7 +389,7 @@ describe("test CSSImage", function() { "$img_t-s2__height: 150px;\n" + "$img_t-s2__path: 'root/t.png';\n"; - cssimage([{ width: 400, height: 300, file: "t.png"}], { + cssimage([{ width: 400, height: 300, file: "t.png" }], { scss: true, retina: true, squeeze: 2,