Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add two rules #700

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
July 10, 2017 - v1.0.5



July 15, 2016 - v1.0.0

* Update parser-lib to v1.0.0. (XhmikosR)
Expand Down
4 changes: 2 additions & 2 deletions dist/cli.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
Expand Down
72 changes: 69 additions & 3 deletions dist/csslint-node.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(/[_]/.test(text)){
reporter.report("Rule name must concat with -.", selectors[i].line, selectors[i].col, rule);
return;
}
}
});
}

});
CSSLint.addRule({

// rule information
Expand Down
112 changes: 86 additions & 26 deletions dist/csslint-rhino.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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') {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(/[_]/.test(text)){
reporter.report("Rule name must concat with -.", selectors[i].line, selectors[i].col, rule);
return;
}
}
});
}

});
CSSLint.addRule({

// rule information
Expand Down
36 changes: 36 additions & 0 deletions dist/csslint-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,42 @@ 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 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;
Expand Down
Loading