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

feat(avoid-inline-spacing): add option for which css properties to look at #2244

Merged
merged 2 commits into from
May 26, 2020
Merged
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
10 changes: 2 additions & 8 deletions lib/checks/shared/avoid-inline-spacing-evaluate.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
function avoidInlineSpacingEvaluate(node) {
const inlineSpacingCssProperties = [
'line-height',
'letter-spacing',
'word-spacing'
];

const overriddenProperties = inlineSpacingCssProperties.filter(property => {
function avoidInlineSpacingEvaluate(node, options) {
const overriddenProperties = options.cssProperties.filter(property => {
if (node.style.getPropertyPriority(property) === `important`) {
return property;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/checks/shared/avoid-inline-spacing.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"id": "avoid-inline-spacing",
"evaluate": "avoid-inline-spacing-evaluate",
"options": {
"cssProperties": ["line-height", "letter-spacing", "word-spacing"]
},
"metadata": {
"impact": "serious",
"messages": {
Expand Down
37 changes: 24 additions & 13 deletions test/checks/shared/avoid-inline-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ describe('avoid-inline-spacing tests', function() {

var fixture = document.getElementById('fixture');
var queryFixture = axe.testUtils.queryFixture;
var check = checks['avoid-inline-spacing'];
var checkEvaluate = axe.testUtils.getCheckEvaluate('avoid-inline-spacing');
var checkContext = axe.testUtils.MockCheckContext();

afterEach(function() {
Expand All @@ -15,7 +15,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="font-size: 200%;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isTrue(actual);
assert.isNull(checkContext._data);
});
Expand All @@ -24,7 +24,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="line-height: 5invalid;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isTrue(actual);
assert.isNull(checkContext._data);
});
Expand All @@ -33,7 +33,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="line-height: invalid !important;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isTrue(actual);
assert.isNull(checkContext._data);
});
Expand All @@ -42,7 +42,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="line-height: 1.5;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isTrue(actual);
assert.isNull(checkContext._data);
});
Expand All @@ -51,7 +51,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="letter-spacing: 50px;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isTrue(actual);
assert.isNull(checkContext._data);
});
Expand All @@ -60,7 +60,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="word-spacing: 10px;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isTrue(actual);
assert.isNull(checkContext._data);
});
Expand All @@ -69,7 +69,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="word-spacing: 20ch; letter-spacing: 50rem; line-height: 3;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isTrue(actual);
assert.isNull(checkContext._data);
});
Expand All @@ -78,7 +78,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="line-height: 1.5 !important;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isFalse(actual);
assert.deepEqual(checkContext._data, ['line-height']);
});
Expand All @@ -87,7 +87,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="letter-spacing: 100em !important;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isFalse(actual);
assert.deepEqual(checkContext._data, ['letter-spacing']);
});
Expand All @@ -96,7 +96,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="word-spacing: -.4ch !important;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isFalse(actual);
assert.deepEqual(checkContext._data, ['word-spacing']);
});
Expand All @@ -105,7 +105,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="word-spacing: 200%; letter-spacing: 50rem !important; line-height: 3;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isFalse(actual);
assert.deepEqual(checkContext._data, ['letter-spacing']);
});
Expand All @@ -114,8 +114,19 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="line-height: 3 !important; letter-spacing: 50rem !important;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isFalse(actual);
assert.deepEqual(checkContext._data, ['line-height', 'letter-spacing']);
});

it('supports options.cssProperties', function() {
var vNode = queryFixture(
'<p id="target" style="font-size: 14px !important; line-height: 3 !important; letter-spacing: 50rem !important">The quick brown fox jumped over the lazy dog</p>'
);
var actual = checkEvaluate.call(checkContext, vNode.actualNode, {
cssProperties: ['font-size']
});
assert.isFalse(actual);
assert.deepEqual(checkContext._data, ['font-size']);
});
});