Skip to content

Commit

Permalink
feat: add more ignored attributes and callee
Browse files Browse the repository at this point in the history
  • Loading branch information
emroussel committed Oct 3, 2019
1 parent 3550d44 commit 0f9e2ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
13 changes: 10 additions & 3 deletions lib/rules/no-literal-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ module.exports = {

const ignoredAttributes = (option && option.ignoreAttribute) || [];
const atts = [
'className', 'style', 'styleName', 'src', 'type', 'id',
'className', 'style', 'styleName', 'src', 'type', 'id', 'target', 'href', 'for', 'form', 'rel', 'tabIndex',
'aria-labelledby', 'role',
// SVG related attributes.
'viewBox', 'cx', 'cy', 'r', 'rx', 'ry', 'd', 'x1', 'y1', 'x2', 'y2', 'fill', 'stroke', 'strokeWidth', 'points',
'viewBox', 'cx', 'cy', 'r', 'rx', 'ry', 'd', 'x1', 'y1', 'x2', 'y2', 'fill', 'fillRule', 'stroke', 'strokeWidth',
'strokeLinejoin', 'strokeLinecap', 'points', 'transform', 'width', 'height',

...ignoredAttributes
];
Expand Down Expand Up @@ -294,6 +296,9 @@ module.exports = {

const popularCallee = [
'addEventListener',
'removeEventListener',
'postMessage',
'getElementById',
//
// ─── VUEX CALLEE ────────────────────────────────────────────────────────────────
//
Expand All @@ -302,7 +307,9 @@ const popularCallee = [
// ────────────────────────────────────────────────────────────────────────────────

'includes',
'indexOf'
'indexOf',
'endsWith',
'startsWith'
];
function generateCalleeWhitelists(option) {
const ignoreCallee = (option && option.ignoreCallee) || [];
Expand Down
16 changes: 14 additions & 2 deletions tests/lib/rules/no-literal-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ ruleTester.run('no-literal-string', rule, {
{ code: 'import name from "hello";' },
{ code: 'a.indexOf("ios")' },
{ code: 'a.includes("ios")' },
{ code: 'a.startsWith("ios")' },
{ code: 'a.endsWith("@gmail.com")' },
{ code: 'export * from "hello_export_all";' },
{ code: 'export { a } from "hello_export";' },
{ code: 'document.addEventListener("click", (event) => { event.preventDefault() })' },
{ code: 'document.removeEventListener("click", (event) => { event.preventDefault() })' },
{ code: 'window.postMessage("message", "*")' },
{ code: 'document.getElementById("some-id")' },
{ code: 'require("hello");' },
{ code: 'const a = require(["hello"]);' },
{ code: 'const a = require(["hel" + "lo"]);' },
Expand All @@ -62,7 +67,12 @@ ruleTester.run('no-literal-string', rule, {
{ code: '<svg viewBox="0 0 20 40"></svg>' },
{ code: '<line x1="0" y1="0" x2="10" y2="20" />' },
{ code: '<path d="M10 10" />' },
{ code: '<circle cx="10" cy="10" r="2" fill="red" />' },
{ code: '<circle width="16px" height="16px" cx="10" cy="10" r="2" fill="red" />' },
{ code: '<a href="https://google.com" target="_blank" rel="noreferrer noopener"></a>' },
{ code: '<div id="some-id" tabIndex="0" aria-labelledby="label-id"></div>' },
{ code: '<div role="button"></div>' },
{ code: '<img src="./image.png" />' },
{ code: '<button type="button" for="form-id" />' },
{ code: '<div foo="bar" />', options: [{ ignoreAttribute: ['foo'] }] }
],

Expand All @@ -80,7 +90,9 @@ ruleTester.run('no-literal-string', rule, {
// JSX
{ code: '<div>foo</div>', errors },
{ code: '<div>FOO</div>', errors },
{ code: '<div foo="bar" />', errors }
{ code: '<div foo="bar" />', errors },
{ code: '<img src="./image.png" alt="some-image" />', errors },
{ code: '<button aria-label="Close" type="button" />', errors }
]
});

Expand Down

0 comments on commit 0f9e2ec

Please sign in to comment.