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 better outline support #724

Open
wants to merge 1 commit 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
23 changes: 17 additions & 6 deletions dist/csslint-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1820,7 +1820,7 @@ CSSLint.addRule({
// rule information
id: "outline-none",
name: "Disallow outline: none",
desc: "Use of outline: none or outline: 0 should be limited to :focus rules.",
desc: "Use of outline: none | 0 | transparent should be limited to :focus rules and resulting elements should be visible.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-outline%3Anone",
browsers: "All",
tags: ["Accessibility"],
Expand All @@ -1838,7 +1838,8 @@ CSSLint.addRule({
col: event.col,
selectors: event.selectors,
propCount: 0,
outline: false
outline: false,
potentiallyInvisibleElement: false
};
} else {
lastRule = null;
Expand All @@ -1850,7 +1851,7 @@ CSSLint.addRule({
if (lastRule.outline) {
if (lastRule.selectors.toString().toLowerCase().indexOf(":focus") === -1) {
reporter.report("Outlines should only be modified using :focus.", lastRule.line, lastRule.col, rule);
} else if (lastRule.propCount === 1) {
} else if (lastRule.propCount === 1 || lastRule.potentiallyInvisibleElement === true) {
reporter.report("Outlines shouldn't be hidden unless other visual changes are made.", lastRule.line, lastRule.col, rule);
}
}
Expand All @@ -1865,13 +1866,23 @@ CSSLint.addRule({
parser.addListener("startviewport", startRule);

parser.addListener("property", function(event) {

var name = event.property.text.toLowerCase(),
value = event.value;
valueString = event.value.toString().toLowerCase();

if (lastRule) {
lastRule.propCount++;
if (name === "outline" && (value.toString() === "none" || value.toString() === "0")) {
lastRule.outline = true;

if (valueString.indexOf("none") !== -1 || valueString.indexOf("0") !== -1 || valueString.indexOf("transparent") !== -1) {
if (name === "outline") {
lastRule.outline = true;
}
else {
// these properties must not be 0, none, or transparent when outline is already one of those values
if (name.indexOf("border") >= 0) {
lastRule.potentiallyInvisibleElement = true;
}
}
}
}

Expand Down
23 changes: 17 additions & 6 deletions dist/csslint-rhino.js
Original file line number Diff line number Diff line change
Expand Up @@ -9378,7 +9378,7 @@ CSSLint.addRule({
// rule information
id: "outline-none",
name: "Disallow outline: none",
desc: "Use of outline: none or outline: 0 should be limited to :focus rules.",
desc: "Use of outline: none | 0 | transparent should be limited to :focus rules and resulting elements should be visible.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-outline%3Anone",
browsers: "All",
tags: ["Accessibility"],
Expand All @@ -9396,7 +9396,8 @@ CSSLint.addRule({
col: event.col,
selectors: event.selectors,
propCount: 0,
outline: false
outline: false,
potentiallyInvisibleElement: false
};
} else {
lastRule = null;
Expand All @@ -9408,7 +9409,7 @@ CSSLint.addRule({
if (lastRule.outline) {
if (lastRule.selectors.toString().toLowerCase().indexOf(":focus") === -1) {
reporter.report("Outlines should only be modified using :focus.", lastRule.line, lastRule.col, rule);
} else if (lastRule.propCount === 1) {
} else if (lastRule.propCount === 1 || lastRule.potentiallyInvisibleElement === true) {
reporter.report("Outlines shouldn't be hidden unless other visual changes are made.", lastRule.line, lastRule.col, rule);
}
}
Expand All @@ -9423,13 +9424,23 @@ CSSLint.addRule({
parser.addListener("startviewport", startRule);

parser.addListener("property", function(event) {

var name = event.property.text.toLowerCase(),
value = event.value;
valueString = event.value.toString().toLowerCase();

if (lastRule) {
lastRule.propCount++;
if (name === "outline" && (value.toString() === "none" || value.toString() === "0")) {
lastRule.outline = true;

if (valueString.indexOf("none") !== -1 || valueString.indexOf("0") !== -1 || valueString.indexOf("transparent") !== -1) {
if (name === "outline") {
lastRule.outline = true;
}
else {
// these properties must not be 0, none, or transparent when outline is already one of those values
if (name.indexOf("border") >= 0) {
lastRule.potentiallyInvisibleElement = true;
}
}
}
}

Expand Down
52 changes: 49 additions & 3 deletions dist/csslint-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3096,6 +3096,13 @@ background: -o-linear-gradient(top, #1e5799 ,#2989d8 ,#207cca ,#7db9e8 );
Assert.areEqual("Outlines should only be modified using :focus.", result.messages[0].message);
},

"Using outline: transparent should result in a warning": function() {
var result = CSSLint.verify(".foo { outline: transparent}", { "outline-none": 1 });
Assert.areEqual(1, result.messages.length);
Assert.areEqual("warning", result.messages[0].type);
Assert.areEqual("Outlines should only be modified using :focus.", result.messages[0].message);
},

"Using outline: 0 should result in a warning": function() {
var result = CSSLint.verify(".foo { outline: 0; }", { "outline-none": 1 });
Assert.areEqual(1, result.messages.length);
Expand All @@ -3117,16 +3124,55 @@ background: -o-linear-gradient(top, #1e5799 ,#2989d8 ,#207cca ,#7db9e8 );
Assert.areEqual("Outlines shouldn't be hidden unless other visual changes are made.", result.messages[0].message);
},

"Using outline: none with :focus and another property should not result in a warning": function() {
"Using outline: transparent alone with :focus should result in a warning": function() {
var result = CSSLint.verify(".foo:focus { outline: transparent; }", { "outline-none": 1 });
Assert.areEqual(1, result.messages.length);
Assert.areEqual("warning", result.messages[0].type);
Assert.areEqual("Outlines shouldn't be hidden unless other visual changes are made.", result.messages[0].message);
},

"Using outline: none with :focus and another visible property should not result in a warning": function() {
var result = CSSLint.verify(".foo:focus { outline: none; border: 1px solid black; }", { "outline-none": 1 });
Assert.areEqual(0, result.messages.length);
},

"Using outline: 0 with :focus and another property should not result in a warning": function() {
"Using outline: 0 with :focus and another visible property should not result in a warning": function() {
var result = CSSLint.verify(".foo:focus { outline: 0; border: 1px solid black;}", { "outline-none": 1 });
Assert.areEqual(0, result.messages.length);
}
},

"Using outline: 1px solid transparent; with :focus should result in a warning": function() {
var result = CSSLint.verify(".foo:focus { outline: 1px solid transparent;}", { "outline-none": 1 });
Assert.areEqual(1, result.messages.length);
Assert.areEqual("warning", result.messages[0].type);
Assert.areEqual("Outlines shouldn't be hidden unless other visual changes are made.", result.messages[0].message);
},

"Using outline: 0 with :focus and another transparent property should result in a warning": function() {
var result = CSSLint.verify(".foo:focus { outline: 0; border: 1px solid transparent;}", { "outline-none": 1 });
Assert.areEqual(1, result.messages.length);
Assert.areEqual("warning", result.messages[0].type);
Assert.areEqual("Outlines shouldn't be hidden unless other visual changes are made.", result.messages[0].message);
},

"Using outline: 0 with :focus and another zeroed property should result in a warning": function() {
var result = CSSLint.verify(".foo:focus { outline: 0; border: 0 solid black;}", { "outline-none": 1 });
Assert.areEqual(1, result.messages.length);
Assert.areEqual("warning", result.messages[0].type);
Assert.areEqual("Outlines shouldn't be hidden unless other visual changes are made.", result.messages[0].message);
},

"Using outline: 0 red; with :focus should result in a warning": function() {
var result = CSSLint.verify(".foo:focus { outline: 0 red;}", { "outline-none": 1 });
Assert.areEqual(1, result.messages.length);
Assert.areEqual("warning", result.messages[0].type);
Assert.areEqual("Outlines shouldn't be hidden unless other visual changes are made.", result.messages[0].message);
},

"Using outline: 0 with :focus and another zeroed property that does not affect rendering should not result in a warning": function() {
var result = CSSLint.verify(".foo:focus { outline: 0; margin: 0;}", { "outline-none": 1 });
Assert.areEqual(0, result.messages.length);
}
}));

})();
Expand Down
23 changes: 17 additions & 6 deletions dist/csslint-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9374,7 +9374,7 @@ CSSLint.addRule({
// rule information
id: "outline-none",
name: "Disallow outline: none",
desc: "Use of outline: none or outline: 0 should be limited to :focus rules.",
desc: "Use of outline: none | 0 | transparent should be limited to :focus rules and resulting elements should be visible.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-outline%3Anone",
browsers: "All",
tags: ["Accessibility"],
Expand All @@ -9392,7 +9392,8 @@ CSSLint.addRule({
col: event.col,
selectors: event.selectors,
propCount: 0,
outline: false
outline: false,
potentiallyInvisibleElement: false
};
} else {
lastRule = null;
Expand All @@ -9404,7 +9405,7 @@ CSSLint.addRule({
if (lastRule.outline) {
if (lastRule.selectors.toString().toLowerCase().indexOf(":focus") === -1) {
reporter.report("Outlines should only be modified using :focus.", lastRule.line, lastRule.col, rule);
} else if (lastRule.propCount === 1) {
} else if (lastRule.propCount === 1 || lastRule.potentiallyInvisibleElement === true) {
reporter.report("Outlines shouldn't be hidden unless other visual changes are made.", lastRule.line, lastRule.col, rule);
}
}
Expand All @@ -9419,13 +9420,23 @@ CSSLint.addRule({
parser.addListener("startviewport", startRule);

parser.addListener("property", function(event) {

var name = event.property.text.toLowerCase(),
value = event.value;
valueString = event.value.toString().toLowerCase();

if (lastRule) {
lastRule.propCount++;
if (name === "outline" && (value.toString() === "none" || value.toString() === "0")) {
lastRule.outline = true;

if (valueString.indexOf("none") !== -1 || valueString.indexOf("0") !== -1 || valueString.indexOf("transparent") !== -1) {
if (name === "outline") {
lastRule.outline = true;
}
else {
// these properties must not be 0, none, or transparent when outline is already one of those values
if (name.indexOf("border") >= 0) {
lastRule.potentiallyInvisibleElement = true;
}
}
}
}

Expand Down
23 changes: 17 additions & 6 deletions dist/csslint-wsh.js
Original file line number Diff line number Diff line change
Expand Up @@ -9378,7 +9378,7 @@ CSSLint.addRule({
// rule information
id: "outline-none",
name: "Disallow outline: none",
desc: "Use of outline: none or outline: 0 should be limited to :focus rules.",
desc: "Use of outline: none | 0 | transparent should be limited to :focus rules and resulting elements should be visible.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-outline%3Anone",
browsers: "All",
tags: ["Accessibility"],
Expand All @@ -9396,7 +9396,8 @@ CSSLint.addRule({
col: event.col,
selectors: event.selectors,
propCount: 0,
outline: false
outline: false,
potentiallyInvisibleElement: false
};
} else {
lastRule = null;
Expand All @@ -9408,7 +9409,7 @@ CSSLint.addRule({
if (lastRule.outline) {
if (lastRule.selectors.toString().toLowerCase().indexOf(":focus") === -1) {
reporter.report("Outlines should only be modified using :focus.", lastRule.line, lastRule.col, rule);
} else if (lastRule.propCount === 1) {
} else if (lastRule.propCount === 1 || lastRule.potentiallyInvisibleElement === true) {
reporter.report("Outlines shouldn't be hidden unless other visual changes are made.", lastRule.line, lastRule.col, rule);
}
}
Expand All @@ -9423,13 +9424,23 @@ CSSLint.addRule({
parser.addListener("startviewport", startRule);

parser.addListener("property", function(event) {

var name = event.property.text.toLowerCase(),
value = event.value;
valueString = event.value.toString().toLowerCase();

if (lastRule) {
lastRule.propCount++;
if (name === "outline" && (value.toString() === "none" || value.toString() === "0")) {
lastRule.outline = true;

if (valueString.indexOf("none") !== -1 || valueString.indexOf("0") !== -1 || valueString.indexOf("transparent") !== -1) {
if (name === "outline") {
lastRule.outline = true;
}
else {
// these properties must not be 0, none, or transparent when outline is already one of those values
if (name.indexOf("border") >= 0) {
lastRule.potentiallyInvisibleElement = true;
}
}
}
}

Expand Down
23 changes: 17 additions & 6 deletions dist/csslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -9378,7 +9378,7 @@ CSSLint.addRule({
// rule information
id: "outline-none",
name: "Disallow outline: none",
desc: "Use of outline: none or outline: 0 should be limited to :focus rules.",
desc: "Use of outline: none | 0 | transparent should be limited to :focus rules and resulting elements should be visible.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-outline%3Anone",
browsers: "All",
tags: ["Accessibility"],
Expand All @@ -9396,7 +9396,8 @@ CSSLint.addRule({
col: event.col,
selectors: event.selectors,
propCount: 0,
outline: false
outline: false,
potentiallyInvisibleElement: false
};
} else {
lastRule = null;
Expand All @@ -9408,7 +9409,7 @@ CSSLint.addRule({
if (lastRule.outline) {
if (lastRule.selectors.toString().toLowerCase().indexOf(":focus") === -1) {
reporter.report("Outlines should only be modified using :focus.", lastRule.line, lastRule.col, rule);
} else if (lastRule.propCount === 1) {
} else if (lastRule.propCount === 1 || lastRule.potentiallyInvisibleElement === true) {
reporter.report("Outlines shouldn't be hidden unless other visual changes are made.", lastRule.line, lastRule.col, rule);
}
}
Expand All @@ -9423,13 +9424,23 @@ CSSLint.addRule({
parser.addListener("startviewport", startRule);

parser.addListener("property", function(event) {

var name = event.property.text.toLowerCase(),
value = event.value;
valueString = event.value.toString().toLowerCase();

if (lastRule) {
lastRule.propCount++;
if (name === "outline" && (value.toString() === "none" || value.toString() === "0")) {
lastRule.outline = true;

if (valueString.indexOf("none") !== -1 || valueString.indexOf("0") !== -1 || valueString.indexOf("transparent") !== -1) {
if (name === "outline") {
lastRule.outline = true;
}
else {
// these properties must not be 0, none, or transparent when outline is already one of those values
if (name.indexOf("border") >= 0) {
lastRule.potentiallyInvisibleElement = true;
}
}
}
}

Expand Down
Loading