From 28287240b9cae7ff1f7461df7c8287cb9ea64517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=B5=A9?= Date: Mon, 10 Jul 2017 17:25:35 +0800 Subject: [PATCH 1/2] Update --- CHANGELOG | 4 + dist/cli.js | 4 +- dist/csslint-node.js | 72 ++++++++++++++++- dist/csslint-rhino.js | 112 ++++++++++++++++++++------ dist/csslint-tests.js | 42 ++++++++++ dist/csslint-worker.js | 112 ++++++++++++++++++++------ dist/csslint-wsh.js | 112 ++++++++++++++++++++------ dist/csslint.js | 112 ++++++++++++++++++++------ src/rules/ex-multi-rules-newline.js | 38 +++++++++ src/rules/ex-rule-name.js | 28 +++++++ tests/rules/ex-multi-rules-newline.js | 17 ++++ tests/rules/ex-rule-name.js | 23 ++++++ 12 files changed, 567 insertions(+), 109 deletions(-) create mode 100644 src/rules/ex-multi-rules-newline.js create mode 100644 src/rules/ex-rule-name.js create mode 100644 tests/rules/ex-multi-rules-newline.js create mode 100644 tests/rules/ex-rule-name.js diff --git a/CHANGELOG b/CHANGELOG index ce18dc7b..4bfc6dc6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +July 10, 2017 - v1.0.5 + + + July 15, 2016 - v1.0.0 * Update parser-lib to v1.0.0. (XhmikosR) diff --git a/dist/cli.js b/dist/cli.js index 192d74e9..16f20dda 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -1,7 +1,7 @@ #!/usr/bin/env node /*! -CSSLint v1.0.4 -Copyright (c) 2016 Nicole Sullivan and Nicholas C. Zakas. All rights reserved. +CSSLint v1.0.5 +Copyright (c) 2017 Nicole Sullivan and Nicholas C. Zakas. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal diff --git a/dist/csslint-node.js b/dist/csslint-node.js index 9f880233..f6b8a679 100644 --- a/dist/csslint-node.js +++ b/dist/csslint-node.js @@ -1,6 +1,6 @@ /*! -CSSLint v1.0.4 -Copyright (c) 2016 Nicole Sullivan and Nicholas C. Zakas. All rights reserved. +CSSLint v1.0.5 +Copyright (c) 2017 Nicole Sullivan and Nicholas C. Zakas. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal @@ -41,7 +41,7 @@ var CSSLint = (function() { embeddedRuleset = /\/\*\s*csslint([^\*]*)\*\//, api = new parserlib.util.EventTarget(); - api.version = "1.0.4"; + api.version = "1.0.5"; //------------------------------------------------------------------------- // Rule Management @@ -1303,6 +1303,72 @@ CSSLint.addRule({ }); +CSSLint.addRule({ + + // rule information + id: "multi-rules-newline", + name: "Multi rules must declear in multi lines", + desc: "Multi rules must declear in multi lines", + url: "", + browsers: "All", + + // initialization + init: function(parser, reporter) { + "use strict"; + var rule = this; + + parser.addListener("startrule", function(event) { + var selectors = event.selectors; + // console.log(selectors); + // console.log('*********************************************'); + // console.log(selectors[0].line); + // console.log(selectors[0].text); + // console.log(selectors[1].line); + // console.log(selectors[1].text); + //如果有多个rules + if (selectors.length > 1) { + var lines = []; + for (var i = 0; i < selectors.length; i++) { + var line = selectors[i].line; + if(lines.indexOf(line) !== -1){ + reporter.report("Multi rules must declear in multi lines.", selectors[i].line, selectors[i].col, rule); + return; + } + lines.push(line); + } + } + }); + } + +}); +CSSLint.addRule({ + + // rule information + id: "rule-name", + name: "Rule name must concat with -", + desc: "Rule name must concat with -", + url: "", + browsers: "All", + + // initialization + init: function(parser, reporter) { + "use strict"; + var rule = this; + + parser.addListener("startrule", function(event) { + var selectors = event.selectors; + + for (var i = 0; i < selectors.length; i++) { + var text = selectors[i].text; + if(/[A-Z_]/.test(text)){ + reporter.report("Rule name must concat with -.", selectors[i].line, selectors[i].col, rule); + return; + } + } + }); + } + +}); CSSLint.addRule({ // rule information diff --git a/dist/csslint-rhino.js b/dist/csslint-rhino.js index 2d01634c..456e87b7 100644 --- a/dist/csslint-rhino.js +++ b/dist/csslint-rhino.js @@ -1,6 +1,6 @@ /*! -CSSLint v1.0.4 -Copyright (c) 2016 Nicole Sullivan and Nicholas C. Zakas. All rights reserved. +CSSLint v1.0.5 +Copyright (c) 2017 Nicole Sullivan and Nicholas C. Zakas. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal @@ -7332,6 +7332,10 @@ return require('parserlib'); var clone = (function() { 'use strict'; +function _instanceof(obj, type) { + return type != null && obj instanceof type; +} + var nativeMap; try { nativeMap = Map; @@ -7411,11 +7415,11 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) { return parent; } - if (parent instanceof nativeMap) { + if (_instanceof(parent, nativeMap)) { child = new nativeMap(); - } else if (parent instanceof nativeSet) { + } else if (_instanceof(parent, nativeSet)) { child = new nativeSet(); - } else if (parent instanceof nativePromise) { + } else if (_instanceof(parent, nativePromise)) { child = new nativePromise(function (resolve, reject) { parent.then(function(value) { resolve(_clone(value, depth - 1)); @@ -7434,7 +7438,7 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) { child = new Buffer(parent.length); parent.copy(child); return child; - } else if (parent instanceof Error) { + } else if (_instanceof(parent, Error)) { child = Object.create(parent); } else { if (typeof prototype == 'undefined') { @@ -7457,28 +7461,18 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) { allChildren.push(child); } - if (parent instanceof nativeMap) { - var keyIterator = parent.keys(); - while(true) { - var next = keyIterator.next(); - if (next.done) { - break; - } - var keyChild = _clone(next.value, depth - 1); - var valueChild = _clone(parent.get(next.value), depth - 1); + if (_instanceof(parent, nativeMap)) { + parent.forEach(function(value, key) { + var keyChild = _clone(key, depth - 1); + var valueChild = _clone(value, depth - 1); child.set(keyChild, valueChild); - } + }); } - if (parent instanceof nativeSet) { - var iterator = parent.keys(); - while(true) { - var next = iterator.next(); - if (next.done) { - break; - } - var entryChild = _clone(next.value, depth - 1); + if (_instanceof(parent, nativeSet)) { + parent.forEach(function(value) { + var entryChild = _clone(value, depth - 1); child.add(entryChild); - } + }); } for (var i in parent) { @@ -7605,7 +7599,7 @@ var CSSLint = (function() { embeddedRuleset = /\/\*\s*csslint([^\*]*)\*\//, api = new parserlib.util.EventTarget(); - api.version = "1.0.4"; + api.version = "1.0.5"; //------------------------------------------------------------------------- // Rule Management @@ -8867,6 +8861,72 @@ CSSLint.addRule({ }); +CSSLint.addRule({ + + // rule information + id: "multi-rules-newline", + name: "Multi rules must declear in multi lines", + desc: "Multi rules must declear in multi lines", + url: "", + browsers: "All", + + // initialization + init: function(parser, reporter) { + "use strict"; + var rule = this; + + parser.addListener("startrule", function(event) { + var selectors = event.selectors; + // console.log(selectors); + // console.log('*********************************************'); + // console.log(selectors[0].line); + // console.log(selectors[0].text); + // console.log(selectors[1].line); + // console.log(selectors[1].text); + //如果有多个rules + if (selectors.length > 1) { + var lines = []; + for (var i = 0; i < selectors.length; i++) { + var line = selectors[i].line; + if(lines.indexOf(line) !== -1){ + reporter.report("Multi rules must declear in multi lines.", selectors[i].line, selectors[i].col, rule); + return; + } + lines.push(line); + } + } + }); + } + +}); +CSSLint.addRule({ + + // rule information + id: "rule-name", + name: "Rule name must concat with -", + desc: "Rule name must concat with -", + url: "", + browsers: "All", + + // initialization + init: function(parser, reporter) { + "use strict"; + var rule = this; + + parser.addListener("startrule", function(event) { + var selectors = event.selectors; + + for (var i = 0; i < selectors.length; i++) { + var text = selectors[i].text; + if(/[A-Z_]/.test(text)){ + reporter.report("Rule name must concat with -.", selectors[i].line, selectors[i].col, rule); + return; + } + } + }); + } + +}); CSSLint.addRule({ // rule information diff --git a/dist/csslint-tests.js b/dist/csslint-tests.js index 56d18001..c09b471d 100644 --- a/dist/csslint-tests.js +++ b/dist/csslint-tests.js @@ -1841,6 +1841,48 @@ function include(path, sandbox) { })(); +(function() { + "use strict"; + var Assert = YUITest.Assert; + + YUITest.TestRunner.add(new YUITest.TestCase({ + + name: "multi-rules-newline", + + "Multi rules must declear in multi lines": function() { + var result = CSSLint.verify(".foo.bar, .hehe { }", { "multi-rules-newline": 1 }); + Assert.areEqual("warning", result.messages[0].type); + Assert.areEqual("Multi rules must declear in multi lines.", result.messages[0].message); + } + + })); + +})(); + +(function() { + "use strict"; + var Assert = YUITest.Assert; + + YUITest.TestRunner.add(new YUITest.TestCase({ + + name: "rule-name", + + "Rule name must concat with -, not use uppercase": function() { + var result = CSSLint.verify(".fooName { }", { "rule-name": 1 }); + Assert.areEqual("warning", result.messages[0].type); + Assert.areEqual("Rule name must concat with -.", result.messages[0].message); + }, + + "Rule name must be concat with -, not _": function() { + var result = CSSLint.verify(".foo_name { }", { "rule-name": 1 }); + Assert.areEqual("warning", result.messages[0].type); + Assert.areEqual("Rule name must concat with -.", result.messages[0].message); + } + + })); + +})(); + (function() { "use strict"; var Assert = YUITest.Assert; diff --git a/dist/csslint-worker.js b/dist/csslint-worker.js index 52602c80..9209f7e4 100644 --- a/dist/csslint-worker.js +++ b/dist/csslint-worker.js @@ -1,6 +1,6 @@ /*! -CSSLint v1.0.4 -Copyright (c) 2016 Nicole Sullivan and Nicholas C. Zakas. All rights reserved. +CSSLint v1.0.5 +Copyright (c) 2017 Nicole Sullivan and Nicholas C. Zakas. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal @@ -7328,6 +7328,10 @@ return require('parserlib'); var clone = (function() { 'use strict'; +function _instanceof(obj, type) { + return type != null && obj instanceof type; +} + var nativeMap; try { nativeMap = Map; @@ -7407,11 +7411,11 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) { return parent; } - if (parent instanceof nativeMap) { + if (_instanceof(parent, nativeMap)) { child = new nativeMap(); - } else if (parent instanceof nativeSet) { + } else if (_instanceof(parent, nativeSet)) { child = new nativeSet(); - } else if (parent instanceof nativePromise) { + } else if (_instanceof(parent, nativePromise)) { child = new nativePromise(function (resolve, reject) { parent.then(function(value) { resolve(_clone(value, depth - 1)); @@ -7430,7 +7434,7 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) { child = new Buffer(parent.length); parent.copy(child); return child; - } else if (parent instanceof Error) { + } else if (_instanceof(parent, Error)) { child = Object.create(parent); } else { if (typeof prototype == 'undefined') { @@ -7453,28 +7457,18 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) { allChildren.push(child); } - if (parent instanceof nativeMap) { - var keyIterator = parent.keys(); - while(true) { - var next = keyIterator.next(); - if (next.done) { - break; - } - var keyChild = _clone(next.value, depth - 1); - var valueChild = _clone(parent.get(next.value), depth - 1); + if (_instanceof(parent, nativeMap)) { + parent.forEach(function(value, key) { + var keyChild = _clone(key, depth - 1); + var valueChild = _clone(value, depth - 1); child.set(keyChild, valueChild); - } + }); } - if (parent instanceof nativeSet) { - var iterator = parent.keys(); - while(true) { - var next = iterator.next(); - if (next.done) { - break; - } - var entryChild = _clone(next.value, depth - 1); + if (_instanceof(parent, nativeSet)) { + parent.forEach(function(value) { + var entryChild = _clone(value, depth - 1); child.add(entryChild); - } + }); } for (var i in parent) { @@ -7601,7 +7595,7 @@ var CSSLint = (function() { embeddedRuleset = /\/\*\s*csslint([^\*]*)\*\//, api = new parserlib.util.EventTarget(); - api.version = "1.0.4"; + api.version = "1.0.5"; //------------------------------------------------------------------------- // Rule Management @@ -8863,6 +8857,72 @@ CSSLint.addRule({ }); +CSSLint.addRule({ + + // rule information + id: "multi-rules-newline", + name: "Multi rules must declear in multi lines", + desc: "Multi rules must declear in multi lines", + url: "", + browsers: "All", + + // initialization + init: function(parser, reporter) { + "use strict"; + var rule = this; + + parser.addListener("startrule", function(event) { + var selectors = event.selectors; + // console.log(selectors); + // console.log('*********************************************'); + // console.log(selectors[0].line); + // console.log(selectors[0].text); + // console.log(selectors[1].line); + // console.log(selectors[1].text); + //如果有多个rules + if (selectors.length > 1) { + var lines = []; + for (var i = 0; i < selectors.length; i++) { + var line = selectors[i].line; + if(lines.indexOf(line) !== -1){ + reporter.report("Multi rules must declear in multi lines.", selectors[i].line, selectors[i].col, rule); + return; + } + lines.push(line); + } + } + }); + } + +}); +CSSLint.addRule({ + + // rule information + id: "rule-name", + name: "Rule name must concat with -", + desc: "Rule name must concat with -", + url: "", + browsers: "All", + + // initialization + init: function(parser, reporter) { + "use strict"; + var rule = this; + + parser.addListener("startrule", function(event) { + var selectors = event.selectors; + + for (var i = 0; i < selectors.length; i++) { + var text = selectors[i].text; + if(/[A-Z_]/.test(text)){ + reporter.report("Rule name must concat with -.", selectors[i].line, selectors[i].col, rule); + return; + } + } + }); + } + +}); CSSLint.addRule({ // rule information diff --git a/dist/csslint-wsh.js b/dist/csslint-wsh.js index 816a47f6..eb4b4529 100644 --- a/dist/csslint-wsh.js +++ b/dist/csslint-wsh.js @@ -1,6 +1,6 @@ /*! -CSSLint v1.0.4 -Copyright (c) 2016 Nicole Sullivan and Nicholas C. Zakas. All rights reserved. +CSSLint v1.0.5 +Copyright (c) 2017 Nicole Sullivan and Nicholas C. Zakas. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal @@ -7332,6 +7332,10 @@ return require('parserlib'); var clone = (function() { 'use strict'; +function _instanceof(obj, type) { + return type != null && obj instanceof type; +} + var nativeMap; try { nativeMap = Map; @@ -7411,11 +7415,11 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) { return parent; } - if (parent instanceof nativeMap) { + if (_instanceof(parent, nativeMap)) { child = new nativeMap(); - } else if (parent instanceof nativeSet) { + } else if (_instanceof(parent, nativeSet)) { child = new nativeSet(); - } else if (parent instanceof nativePromise) { + } else if (_instanceof(parent, nativePromise)) { child = new nativePromise(function (resolve, reject) { parent.then(function(value) { resolve(_clone(value, depth - 1)); @@ -7434,7 +7438,7 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) { child = new Buffer(parent.length); parent.copy(child); return child; - } else if (parent instanceof Error) { + } else if (_instanceof(parent, Error)) { child = Object.create(parent); } else { if (typeof prototype == 'undefined') { @@ -7457,28 +7461,18 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) { allChildren.push(child); } - if (parent instanceof nativeMap) { - var keyIterator = parent.keys(); - while(true) { - var next = keyIterator.next(); - if (next.done) { - break; - } - var keyChild = _clone(next.value, depth - 1); - var valueChild = _clone(parent.get(next.value), depth - 1); + if (_instanceof(parent, nativeMap)) { + parent.forEach(function(value, key) { + var keyChild = _clone(key, depth - 1); + var valueChild = _clone(value, depth - 1); child.set(keyChild, valueChild); - } + }); } - if (parent instanceof nativeSet) { - var iterator = parent.keys(); - while(true) { - var next = iterator.next(); - if (next.done) { - break; - } - var entryChild = _clone(next.value, depth - 1); + if (_instanceof(parent, nativeSet)) { + parent.forEach(function(value) { + var entryChild = _clone(value, depth - 1); child.add(entryChild); - } + }); } for (var i in parent) { @@ -7605,7 +7599,7 @@ var CSSLint = (function() { embeddedRuleset = /\/\*\s*csslint([^\*]*)\*\//, api = new parserlib.util.EventTarget(); - api.version = "1.0.4"; + api.version = "1.0.5"; //------------------------------------------------------------------------- // Rule Management @@ -8867,6 +8861,72 @@ CSSLint.addRule({ }); +CSSLint.addRule({ + + // rule information + id: "multi-rules-newline", + name: "Multi rules must declear in multi lines", + desc: "Multi rules must declear in multi lines", + url: "", + browsers: "All", + + // initialization + init: function(parser, reporter) { + "use strict"; + var rule = this; + + parser.addListener("startrule", function(event) { + var selectors = event.selectors; + // console.log(selectors); + // console.log('*********************************************'); + // console.log(selectors[0].line); + // console.log(selectors[0].text); + // console.log(selectors[1].line); + // console.log(selectors[1].text); + //如果有多个rules + if (selectors.length > 1) { + var lines = []; + for (var i = 0; i < selectors.length; i++) { + var line = selectors[i].line; + if(lines.indexOf(line) !== -1){ + reporter.report("Multi rules must declear in multi lines.", selectors[i].line, selectors[i].col, rule); + return; + } + lines.push(line); + } + } + }); + } + +}); +CSSLint.addRule({ + + // rule information + id: "rule-name", + name: "Rule name must concat with -", + desc: "Rule name must concat with -", + url: "", + browsers: "All", + + // initialization + init: function(parser, reporter) { + "use strict"; + var rule = this; + + parser.addListener("startrule", function(event) { + var selectors = event.selectors; + + for (var i = 0; i < selectors.length; i++) { + var text = selectors[i].text; + if(/[A-Z_]/.test(text)){ + reporter.report("Rule name must concat with -.", selectors[i].line, selectors[i].col, rule); + return; + } + } + }); + } + +}); CSSLint.addRule({ // rule information diff --git a/dist/csslint.js b/dist/csslint.js index 665e4a21..c593cd6d 100644 --- a/dist/csslint.js +++ b/dist/csslint.js @@ -1,6 +1,6 @@ /*! -CSSLint v1.0.4 -Copyright (c) 2016 Nicole Sullivan and Nicholas C. Zakas. All rights reserved. +CSSLint v1.0.5 +Copyright (c) 2017 Nicole Sullivan and Nicholas C. Zakas. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal @@ -7332,6 +7332,10 @@ return require('parserlib'); var clone = (function() { 'use strict'; +function _instanceof(obj, type) { + return type != null && obj instanceof type; +} + var nativeMap; try { nativeMap = Map; @@ -7411,11 +7415,11 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) { return parent; } - if (parent instanceof nativeMap) { + if (_instanceof(parent, nativeMap)) { child = new nativeMap(); - } else if (parent instanceof nativeSet) { + } else if (_instanceof(parent, nativeSet)) { child = new nativeSet(); - } else if (parent instanceof nativePromise) { + } else if (_instanceof(parent, nativePromise)) { child = new nativePromise(function (resolve, reject) { parent.then(function(value) { resolve(_clone(value, depth - 1)); @@ -7434,7 +7438,7 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) { child = new Buffer(parent.length); parent.copy(child); return child; - } else if (parent instanceof Error) { + } else if (_instanceof(parent, Error)) { child = Object.create(parent); } else { if (typeof prototype == 'undefined') { @@ -7457,28 +7461,18 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) { allChildren.push(child); } - if (parent instanceof nativeMap) { - var keyIterator = parent.keys(); - while(true) { - var next = keyIterator.next(); - if (next.done) { - break; - } - var keyChild = _clone(next.value, depth - 1); - var valueChild = _clone(parent.get(next.value), depth - 1); + if (_instanceof(parent, nativeMap)) { + parent.forEach(function(value, key) { + var keyChild = _clone(key, depth - 1); + var valueChild = _clone(value, depth - 1); child.set(keyChild, valueChild); - } + }); } - if (parent instanceof nativeSet) { - var iterator = parent.keys(); - while(true) { - var next = iterator.next(); - if (next.done) { - break; - } - var entryChild = _clone(next.value, depth - 1); + if (_instanceof(parent, nativeSet)) { + parent.forEach(function(value) { + var entryChild = _clone(value, depth - 1); child.add(entryChild); - } + }); } for (var i in parent) { @@ -7605,7 +7599,7 @@ var CSSLint = (function() { embeddedRuleset = /\/\*\s*csslint([^\*]*)\*\//, api = new parserlib.util.EventTarget(); - api.version = "1.0.4"; + api.version = "1.0.5"; //------------------------------------------------------------------------- // Rule Management @@ -8867,6 +8861,72 @@ CSSLint.addRule({ }); +CSSLint.addRule({ + + // rule information + id: "multi-rules-newline", + name: "Multi rules must declear in multi lines", + desc: "Multi rules must declear in multi lines", + url: "", + browsers: "All", + + // initialization + init: function(parser, reporter) { + "use strict"; + var rule = this; + + parser.addListener("startrule", function(event) { + var selectors = event.selectors; + // console.log(selectors); + // console.log('*********************************************'); + // console.log(selectors[0].line); + // console.log(selectors[0].text); + // console.log(selectors[1].line); + // console.log(selectors[1].text); + //如果有多个rules + if (selectors.length > 1) { + var lines = []; + for (var i = 0; i < selectors.length; i++) { + var line = selectors[i].line; + if(lines.indexOf(line) !== -1){ + reporter.report("Multi rules must declear in multi lines.", selectors[i].line, selectors[i].col, rule); + return; + } + lines.push(line); + } + } + }); + } + +}); +CSSLint.addRule({ + + // rule information + id: "rule-name", + name: "Rule name must concat with -", + desc: "Rule name must concat with -", + url: "", + browsers: "All", + + // initialization + init: function(parser, reporter) { + "use strict"; + var rule = this; + + parser.addListener("startrule", function(event) { + var selectors = event.selectors; + + for (var i = 0; i < selectors.length; i++) { + var text = selectors[i].text; + if(/[A-Z_]/.test(text)){ + reporter.report("Rule name must concat with -.", selectors[i].line, selectors[i].col, rule); + return; + } + } + }); + } + +}); CSSLint.addRule({ // rule information diff --git a/src/rules/ex-multi-rules-newline.js b/src/rules/ex-multi-rules-newline.js new file mode 100644 index 00000000..eb712e88 --- /dev/null +++ b/src/rules/ex-multi-rules-newline.js @@ -0,0 +1,38 @@ +CSSLint.addRule({ + + // rule information + id: "multi-rules-newline", + name: "Multi rules must declear in multi lines", + desc: "Multi rules must declear in multi lines", + url: "", + browsers: "All", + + // initialization + init: function(parser, reporter) { + "use strict"; + var rule = this; + + parser.addListener("startrule", function(event) { + var selectors = event.selectors; + // console.log(selectors); + // console.log('*********************************************'); + // console.log(selectors[0].line); + // console.log(selectors[0].text); + // console.log(selectors[1].line); + // console.log(selectors[1].text); + //如果有多个rules + if (selectors.length > 1) { + var lines = []; + for (var i = 0; i < selectors.length; i++) { + var line = selectors[i].line; + if(lines.indexOf(line) !== -1){ + reporter.report("Multi rules must declear in multi lines.", selectors[i].line, selectors[i].col, rule); + return; + } + lines.push(line); + } + } + }); + } + +}); \ No newline at end of file diff --git a/src/rules/ex-rule-name.js b/src/rules/ex-rule-name.js new file mode 100644 index 00000000..b588a8f0 --- /dev/null +++ b/src/rules/ex-rule-name.js @@ -0,0 +1,28 @@ +CSSLint.addRule({ + + // rule information + id: "rule-name", + name: "Rule name must concat with -", + desc: "Rule name must concat with -", + url: "", + browsers: "All", + + // initialization + init: function(parser, reporter) { + "use strict"; + var rule = this; + + parser.addListener("startrule", function(event) { + var selectors = event.selectors; + + for (var i = 0; i < selectors.length; i++) { + var text = selectors[i].text; + if(/[A-Z_]/.test(text)){ + reporter.report("Rule name must concat with -.", selectors[i].line, selectors[i].col, rule); + return; + } + } + }); + } + +}); \ No newline at end of file diff --git a/tests/rules/ex-multi-rules-newline.js b/tests/rules/ex-multi-rules-newline.js new file mode 100644 index 00000000..834b7542 --- /dev/null +++ b/tests/rules/ex-multi-rules-newline.js @@ -0,0 +1,17 @@ +(function() { + "use strict"; + var Assert = YUITest.Assert; + + YUITest.TestRunner.add(new YUITest.TestCase({ + + name: "multi-rules-newline", + + "Multi rules must declear in multi lines": function() { + var result = CSSLint.verify(".foo.bar, .hehe { }", { "multi-rules-newline": 1 }); + Assert.areEqual("warning", result.messages[0].type); + Assert.areEqual("Multi rules must declear in multi lines.", result.messages[0].message); + } + + })); + +})(); diff --git a/tests/rules/ex-rule-name.js b/tests/rules/ex-rule-name.js new file mode 100644 index 00000000..6051003c --- /dev/null +++ b/tests/rules/ex-rule-name.js @@ -0,0 +1,23 @@ +(function() { + "use strict"; + var Assert = YUITest.Assert; + + YUITest.TestRunner.add(new YUITest.TestCase({ + + name: "rule-name", + + "Rule name must concat with -, not use uppercase": function() { + var result = CSSLint.verify(".fooName { }", { "rule-name": 1 }); + Assert.areEqual("warning", result.messages[0].type); + Assert.areEqual("Rule name must concat with -.", result.messages[0].message); + }, + + "Rule name must be concat with -, not _": function() { + var result = CSSLint.verify(".foo_name { }", { "rule-name": 1 }); + Assert.areEqual("warning", result.messages[0].type); + Assert.areEqual("Rule name must concat with -.", result.messages[0].message); + } + + })); + +})(); From 08c2ba410f4bc281332eb55e17f0f0f77f98185f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=B5=A9?= Date: Tue, 11 Jul 2017 15:22:05 +0800 Subject: [PATCH 2/2] Update --- dist/cli.js | 0 dist/csslint-node.js | 2 +- dist/csslint-rhino.js | 2 +- dist/csslint-tests.js | 6 ------ dist/csslint-worker.js | 2 +- dist/csslint-wsh.js | 2 +- dist/csslint.js | 2 +- src/rules/ex-rule-name.js | 2 +- tests/rules/ex-rule-name.js | 6 ------ 9 files changed, 6 insertions(+), 18 deletions(-) mode change 100644 => 100755 dist/cli.js diff --git a/dist/cli.js b/dist/cli.js old mode 100644 new mode 100755 diff --git a/dist/csslint-node.js b/dist/csslint-node.js index f6b8a679..d2011c3e 100644 --- a/dist/csslint-node.js +++ b/dist/csslint-node.js @@ -1360,7 +1360,7 @@ CSSLint.addRule({ for (var i = 0; i < selectors.length; i++) { var text = selectors[i].text; - if(/[A-Z_]/.test(text)){ + if(/[_]/.test(text)){ reporter.report("Rule name must concat with -.", selectors[i].line, selectors[i].col, rule); return; } diff --git a/dist/csslint-rhino.js b/dist/csslint-rhino.js index 456e87b7..4e76547a 100644 --- a/dist/csslint-rhino.js +++ b/dist/csslint-rhino.js @@ -8918,7 +8918,7 @@ CSSLint.addRule({ for (var i = 0; i < selectors.length; i++) { var text = selectors[i].text; - if(/[A-Z_]/.test(text)){ + if(/[_]/.test(text)){ reporter.report("Rule name must concat with -.", selectors[i].line, selectors[i].col, rule); return; } diff --git a/dist/csslint-tests.js b/dist/csslint-tests.js index c09b471d..73425326 100644 --- a/dist/csslint-tests.js +++ b/dist/csslint-tests.js @@ -1867,12 +1867,6 @@ function include(path, sandbox) { name: "rule-name", - "Rule name must concat with -, not use uppercase": function() { - var result = CSSLint.verify(".fooName { }", { "rule-name": 1 }); - Assert.areEqual("warning", result.messages[0].type); - Assert.areEqual("Rule name must concat with -.", result.messages[0].message); - }, - "Rule name must be concat with -, not _": function() { var result = CSSLint.verify(".foo_name { }", { "rule-name": 1 }); Assert.areEqual("warning", result.messages[0].type); diff --git a/dist/csslint-worker.js b/dist/csslint-worker.js index 9209f7e4..86bbcb10 100644 --- a/dist/csslint-worker.js +++ b/dist/csslint-worker.js @@ -8914,7 +8914,7 @@ CSSLint.addRule({ for (var i = 0; i < selectors.length; i++) { var text = selectors[i].text; - if(/[A-Z_]/.test(text)){ + if(/[_]/.test(text)){ reporter.report("Rule name must concat with -.", selectors[i].line, selectors[i].col, rule); return; } diff --git a/dist/csslint-wsh.js b/dist/csslint-wsh.js index eb4b4529..d538f3b9 100644 --- a/dist/csslint-wsh.js +++ b/dist/csslint-wsh.js @@ -8918,7 +8918,7 @@ CSSLint.addRule({ for (var i = 0; i < selectors.length; i++) { var text = selectors[i].text; - if(/[A-Z_]/.test(text)){ + if(/[_]/.test(text)){ reporter.report("Rule name must concat with -.", selectors[i].line, selectors[i].col, rule); return; } diff --git a/dist/csslint.js b/dist/csslint.js index c593cd6d..8f5aa555 100644 --- a/dist/csslint.js +++ b/dist/csslint.js @@ -8918,7 +8918,7 @@ CSSLint.addRule({ for (var i = 0; i < selectors.length; i++) { var text = selectors[i].text; - if(/[A-Z_]/.test(text)){ + if(/[_]/.test(text)){ reporter.report("Rule name must concat with -.", selectors[i].line, selectors[i].col, rule); return; } diff --git a/src/rules/ex-rule-name.js b/src/rules/ex-rule-name.js index b588a8f0..034e85d7 100644 --- a/src/rules/ex-rule-name.js +++ b/src/rules/ex-rule-name.js @@ -17,7 +17,7 @@ CSSLint.addRule({ for (var i = 0; i < selectors.length; i++) { var text = selectors[i].text; - if(/[A-Z_]/.test(text)){ + if(/[_]/.test(text)){ reporter.report("Rule name must concat with -.", selectors[i].line, selectors[i].col, rule); return; } diff --git a/tests/rules/ex-rule-name.js b/tests/rules/ex-rule-name.js index 6051003c..4fb10a96 100644 --- a/tests/rules/ex-rule-name.js +++ b/tests/rules/ex-rule-name.js @@ -6,12 +6,6 @@ name: "rule-name", - "Rule name must concat with -, not use uppercase": function() { - var result = CSSLint.verify(".fooName { }", { "rule-name": 1 }); - Assert.areEqual("warning", result.messages[0].type); - Assert.areEqual("Rule name must concat with -.", result.messages[0].message); - }, - "Rule name must be concat with -, not _": function() { var result = CSSLint.verify(".foo_name { }", { "rule-name": 1 }); Assert.areEqual("warning", result.messages[0].type);