Skip to content

Commit f0b18b5

Browse files
committed
all tests pass
1 parent 1883f0b commit f0b18b5

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

lib/rules/a11y-no-generic-link-text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const {getProp, getPropValue} = require('jsx-ast-utils')
2-
const {getElementType} = require('../utils/get-element-type.js')
2+
const {getElementType} = require('../utils/get-element-type')
33

44
const bannedLinkText = ['read more', 'here', 'click here', 'learn more', 'more', 'here']
55

lib/utils/get-element-type.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ function getElementType(context, node) {
1515
const props = Object.entries(component.props)
1616
for (const [key, value] of props) {
1717
const propMap = value
18-
let propValue = getPropValue(getProp(node.attributes, key))
19-
let mapValue = propMap[propValue]
18+
const propValue = getPropValue(getProp(node.attributes, key))
19+
const mapValue = propMap[propValue]
2020

2121
if (mapValue) {
2222
element = mapValue

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"scripts": {
1313
"pretest": "mkdir -p node_modules/ && ln -fs $(pwd) node_modules/",
1414
"eslint-check": "eslint-config-prettier .eslintrc.js",
15-
"test": "mocha ./tests/**/*.js ./tests/*.js"
15+
"test": "npm run eslint-check && eslint . && mocha tests/**/*.js tests/"
1616
},
1717
"repository": {
1818
"type": "git",
@@ -51,7 +51,6 @@
5151
],
5252
"devDependencies": {
5353
"@github/prettier-config": "0.0.4",
54-
"chai": "^4.3.6",
5554
"eslint": "^8.0.1",
5655
"eslint-plugin-eslint-plugin": "^5.0.0",
5756
"mocha": "^10.0.0"

tests/a11y-no-generic-link-text.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ ruleTester.run('a11y-no-generic-link-text', rule, {
2727
github: {
2828
components: {
2929
Link: {
30-
props: { as: {undefined: 'a'} }
30+
props: {as: {undefined: 'a'}}
3131
}
3232
}
3333
}
3434
}
35-
},
35+
}
3636
],
3737
invalid: [
3838
{
3939
code: '<ButtonLink href="#">Read more</ButtonLink>',
40+
errors: [{message: errorMessage}],
4041
settings: {
4142
github: {
4243
components: {
@@ -45,34 +46,33 @@ ruleTester.run('a11y-no-generic-link-text', rule, {
4546
}
4647
}
4748
}
48-
},
49-
errors: [{message: errorMessage}]
49+
}
5050
},
5151
{
5252
code: '<Link href="#">Read more</Link>',
53+
errors: [{message: errorMessage}],
5354
settings: {
5455
github: {
5556
components: {
5657
Link: {
57-
props: { as: {undefined: 'a'} }
58+
props: {as: {undefined: 'a'}}
5859
}
5960
}
6061
}
61-
},
62-
errors: [{message: errorMessage}]
62+
}
6363
},
6464
{
6565
code: '<Test as="a" href="#">Read more</Test>',
66+
errors: [{message: errorMessage}],
6667
settings: {
6768
github: {
6869
components: {
6970
Test: {
70-
props: { as: {'a': 'a'} }
71+
props: {as: {a: 'a'}}
7172
}
7273
}
7374
}
74-
},
75-
errors: [{message: errorMessage}]
75+
}
7676
},
7777
{
7878
code: "<Box><a href='#'>Click here</a></Box>;",

tests/utils/get-element-type.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
const {getElementType} = require('../../lib/utils/get-element-type')
2+
const mocha = require('mocha')
3+
const describe = mocha.describe
4+
const it = mocha.it
25
const expect = require('chai').expect
36

47
function mockJSXAttribute(prop, propValue) {
@@ -15,7 +18,7 @@ function mockJSXAttribute(prop, propValue) {
1518
}
1619
}
1720

18-
function mockJSXOpeningElement(tagName, attributes = [], children = []) {
21+
function mockJSXOpeningElement(tagName, attributes = []) {
1922
return {
2023
type: 'JSXOpeningElement',
2124
name: {
@@ -37,12 +40,12 @@ function mockSetting(componentSetting = {}) {
3740
}
3841

3942
describe('getElementType', function () {
40-
it('gets element type', function () {
43+
it('returns raw element type', function () {
4144
const node = mockJSXOpeningElement('a')
4245
expect(getElementType({}, node)).to.equal('a')
4346
})
4447

45-
it('gets element type from default', function () {
48+
it('returns element type from default if set', function () {
4649
const node = mockJSXOpeningElement('Link', [mockJSXAttribute('as', 'summary')])
4750
const setting = mockSetting({
4851
Link: {
@@ -52,7 +55,7 @@ describe('getElementType', function () {
5255
expect(getElementType(setting, node)).to.equal('button')
5356
})
5457

55-
it('gets element type from matching props setting', function () {
58+
it('returns element type from matching props setting if set', function () {
5659
const setting = mockSetting({
5760
Link: {
5861
default: 'a',
@@ -61,17 +64,12 @@ describe('getElementType', function () {
6164
}
6265
}
6366
})
64-
const node_1 = mockJSXOpeningElement('Link')
65-
expect(getElementType(setting, node_1)).to.equal('a')
6667

67-
const node_2 = mockJSXOpeningElement('Link', [mockJSXAttribute('as', 'p')])
68-
expect(getElementType(setting, node_2)).to.equal('a')
69-
70-
const node_3 = mockJSXOpeningElement('Link', [mockJSXAttribute('as', 'summary')])
71-
expect(getElementType(setting, node_3)).to.equal('summary')
68+
const node = mockJSXOpeningElement('Link', [mockJSXAttribute('as', 'summary')])
69+
expect(getElementType(setting, node)).to.equal('summary')
7270
})
7371

74-
it('uses original type if no default or matching prop setting', function () {
72+
it('returns raw type if no default or matching prop setting', function () {
7573
const setting = mockSetting({
7674
Link: {
7775
props: {
@@ -95,7 +93,7 @@ describe('getElementType', function () {
9593
expect(getElementType(setting, node)).to.equal('a')
9694
})
9795

98-
it('falls back to original type if no default and prop does not match props setting', function () {
96+
it('returns raw type if prop does not match props setting and no default type', function () {
9997
const setting = mockSetting({
10098
Link: {
10199
props: {

0 commit comments

Comments
 (0)