From 68990d56e7115598e1c6c62b7e9e47426db25d1c Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Thu, 21 May 2020 10:37:57 -0600 Subject: [PATCH 1/2] feat(avoid-inline-spacing): add option for which css properties to look at --- .../shared/avoid-inline-spacing-evaluate.js | 10 +---- lib/checks/shared/avoid-inline-spacing.json | 3 ++ test/checks/shared/avoid-inline-spacing.js | 37 ++++++++++++------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/lib/checks/shared/avoid-inline-spacing-evaluate.js b/lib/checks/shared/avoid-inline-spacing-evaluate.js index 97a86103ce..c0b7c6413d 100644 --- a/lib/checks/shared/avoid-inline-spacing-evaluate.js +++ b/lib/checks/shared/avoid-inline-spacing-evaluate.js @@ -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; } diff --git a/lib/checks/shared/avoid-inline-spacing.json b/lib/checks/shared/avoid-inline-spacing.json index d7d4f79198..be1f3e2d9f 100644 --- a/lib/checks/shared/avoid-inline-spacing.json +++ b/lib/checks/shared/avoid-inline-spacing.json @@ -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": { diff --git a/test/checks/shared/avoid-inline-spacing.js b/test/checks/shared/avoid-inline-spacing.js index ff500bba19..1a4b07e044 100644 --- a/test/checks/shared/avoid-inline-spacing.js +++ b/test/checks/shared/avoid-inline-spacing.js @@ -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() { @@ -15,7 +15,7 @@ describe('avoid-inline-spacing tests', function() { var vNode = queryFixture( '

The quick brown fox jumped over the lazy dog

' ); - var actual = check.evaluate.call(checkContext, vNode.actualNode); + var actual = checkEvaluate.call(checkContext, vNode.actualNode); assert.isTrue(actual); assert.isNull(checkContext._data); }); @@ -24,7 +24,7 @@ describe('avoid-inline-spacing tests', function() { var vNode = queryFixture( '

The quick brown fox jumped over the lazy dog

' ); - var actual = check.evaluate.call(checkContext, vNode.actualNode); + var actual = checkEvaluate.call(checkContext, vNode.actualNode); assert.isTrue(actual); assert.isNull(checkContext._data); }); @@ -33,7 +33,7 @@ describe('avoid-inline-spacing tests', function() { var vNode = queryFixture( '

The quick brown fox jumped over the lazy dog

' ); - var actual = check.evaluate.call(checkContext, vNode.actualNode); + var actual = checkEvaluate.call(checkContext, vNode.actualNode); assert.isTrue(actual); assert.isNull(checkContext._data); }); @@ -42,7 +42,7 @@ describe('avoid-inline-spacing tests', function() { var vNode = queryFixture( '

The quick brown fox jumped over the lazy dog

' ); - var actual = check.evaluate.call(checkContext, vNode.actualNode); + var actual = checkEvaluate.call(checkContext, vNode.actualNode); assert.isTrue(actual); assert.isNull(checkContext._data); }); @@ -51,7 +51,7 @@ describe('avoid-inline-spacing tests', function() { var vNode = queryFixture( '

The quick brown fox jumped over the lazy dog

' ); - var actual = check.evaluate.call(checkContext, vNode.actualNode); + var actual = checkEvaluate.call(checkContext, vNode.actualNode); assert.isTrue(actual); assert.isNull(checkContext._data); }); @@ -60,7 +60,7 @@ describe('avoid-inline-spacing tests', function() { var vNode = queryFixture( '

The quick brown fox jumped over the lazy dog

' ); - var actual = check.evaluate.call(checkContext, vNode.actualNode); + var actual = checkEvaluate.call(checkContext, vNode.actualNode); assert.isTrue(actual); assert.isNull(checkContext._data); }); @@ -69,7 +69,7 @@ describe('avoid-inline-spacing tests', function() { var vNode = queryFixture( '

The quick brown fox jumped over the lazy dog

' ); - var actual = check.evaluate.call(checkContext, vNode.actualNode); + var actual = checkEvaluate.call(checkContext, vNode.actualNode); assert.isTrue(actual); assert.isNull(checkContext._data); }); @@ -78,7 +78,7 @@ describe('avoid-inline-spacing tests', function() { var vNode = queryFixture( '

The quick brown fox jumped over the lazy dog

' ); - var actual = check.evaluate.call(checkContext, vNode.actualNode); + var actual = checkEvaluate.call(checkContext, vNode.actualNode); assert.isFalse(actual); assert.deepEqual(checkContext._data, ['line-height']); }); @@ -87,7 +87,7 @@ describe('avoid-inline-spacing tests', function() { var vNode = queryFixture( '

The quick brown fox jumped over the lazy dog

' ); - var actual = check.evaluate.call(checkContext, vNode.actualNode); + var actual = checkEvaluate.call(checkContext, vNode.actualNode); assert.isFalse(actual); assert.deepEqual(checkContext._data, ['letter-spacing']); }); @@ -96,7 +96,7 @@ describe('avoid-inline-spacing tests', function() { var vNode = queryFixture( '

The quick brown fox jumped over the lazy dog

' ); - var actual = check.evaluate.call(checkContext, vNode.actualNode); + var actual = checkEvaluate.call(checkContext, vNode.actualNode); assert.isFalse(actual); assert.deepEqual(checkContext._data, ['word-spacing']); }); @@ -105,7 +105,7 @@ describe('avoid-inline-spacing tests', function() { var vNode = queryFixture( '

The quick brown fox jumped over the lazy dog

' ); - var actual = check.evaluate.call(checkContext, vNode.actualNode); + var actual = checkEvaluate.call(checkContext, vNode.actualNode); assert.isFalse(actual); assert.deepEqual(checkContext._data, ['letter-spacing']); }); @@ -114,8 +114,19 @@ describe('avoid-inline-spacing tests', function() { var vNode = queryFixture( '

The quick brown fox jumped over the lazy dog

' ); - 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( + '

The quick brown fox jumped over the lazy dog

' + ); + var actual = checkEvaluate.call(checkContext, vNode.actualNode, { + cssProperties: ['font-size'] + }); + assert.isFalse(actual); + assert.deepEqual(checkContext._data, ['font-size']); + }); }); From 4c6563b7aafdfca99d96c65409f8bb2905b65fbe Mon Sep 17 00:00:00 2001 From: Steven Lambert <2433219+straker@users.noreply.github.com> Date: Fri, 22 May 2020 07:59:33 -0600 Subject: [PATCH 2/2] Update test/checks/shared/avoid-inline-spacing.js Co-authored-by: Wilco Fiers --- test/checks/shared/avoid-inline-spacing.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/checks/shared/avoid-inline-spacing.js b/test/checks/shared/avoid-inline-spacing.js index 1a4b07e044..dd626a1194 100644 --- a/test/checks/shared/avoid-inline-spacing.js +++ b/test/checks/shared/avoid-inline-spacing.js @@ -121,7 +121,7 @@ describe('avoid-inline-spacing tests', function() { it('supports options.cssProperties', function() { var vNode = queryFixture( - '

The quick brown fox jumped over the lazy dog

' + '

The quick brown fox jumped over the lazy dog

' ); var actual = checkEvaluate.call(checkContext, vNode.actualNode, { cssProperties: ['font-size']