Skip to content

Commit

Permalink
Merge pull request #6 from alliejones/etsy-fixes
Browse files Browse the repository at this point in the history
Test cases and fixes for some code that prevents linting
  • Loading branch information
david-at-frog authored Feb 13, 2020
2 parents e0b2a48 + 48be78c commit 843b5ba
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/rules/attr-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = {
args[0]
)

if (!BANNED_ATTRS.includes(arg0.value)) { return }
if (!arg0 || !BANNED_ATTRS.includes(arg0.value)) { return }

const sourceCode = context.getSourceCode();

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-attr-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = {
? resolveIdentifier(args[0], context)
: args[0]

if (arg0.type !== 'Literal' || arg0.value !== 'value') return
if (!arg0 || arg0.type !== 'Literal' || arg0.value !== 'value') return

context.report({
node: node.callee.property,
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-null-param.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = {
argumentObject = argumentObject['data']
}

if (typeof argumentObject !== "object") { return }
if (typeof argumentObject !== "object" || argumentObject === null) { return }

let foundBadValue = badValueWalker(BANNED_VALUES)(argumentObject)

Expand Down
6 changes: 6 additions & 0 deletions test/lib/rules/jquery-compat/attr-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ ruleTester.run('jquery-compat/attr-select', rules['attr-select'], {
},
{
code: `(true ? bar : $foo.model()).attr('${property}')`
},
{
code: `function foo(attr) { return $bar.attr(attr); }`
},
{
code: `$.each(["${property}"], function(i, attr) { if (element.attr(attr)) {} });`
}
])
.reduce((acc, next) => acc.concat(next))
Expand Down
3 changes: 3 additions & 0 deletions test/lib/rules/jquery-compat/no-attr-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ ruleTester.run('jquery-compat/no-attr-value', rules['no-attr-value'], {
{
code: `var name = "something-else";
$(".foo").attr(name)`
},
{
code: `$.each(["name"], function(i, attr) { if (element.attr(attr)) {} });`
}
],
invalid: [
Expand Down
3 changes: 3 additions & 0 deletions test/lib/rules/jquery-compat/no-null-param.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ ruleTester.run('jquery-compat/no-null-param', rules['no-null-param'], {
code: `var data = { foo: null };
data.foo = 42;
$.ajax("hello", { data: data });`
},
{
code: `$.ajax({ data: null });`
}
],
invalid: [
Expand Down

0 comments on commit 843b5ba

Please sign in to comment.