Skip to content

Commit

Permalink
custom-error-definition - Fix null reference (#188)
Browse files Browse the repository at this point in the history
Fixes #150
  • Loading branch information
MrHen authored and sindresorhus committed Sep 3, 2018
1 parent f96dd97 commit cf3e22d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
4 changes: 4 additions & 0 deletions rules/custom-error-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const customErrorDefinition = (context, node) => {
return;
}

if (node.id == null) {
return;
}

const {name} = node.id;
const className = getClassName(name);

Expand Down
36 changes: 29 additions & 7 deletions test/custom-error-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,22 @@ ruleTester.run('custom-error-definition', rule, {
this.name = 'FooError';
}
};
`,
`
exports.FooError = class extends Error {
constructor(error) {
super(error);
}
};
`,
`
// `
// exports.FooError = class extends Error {
// constructor(error) {
// super(error);
// }
// };
// `
exports.fooError = class extends Error {
constructor(error) {
super(error);
this.name = 'fooError';
}
};
`,
],
invalid: [
{
Expand Down Expand Up @@ -348,6 +356,20 @@ ruleTester.run('custom-error-definition', rule, {
invalidNameError('FooError')
]
},
// TODO: Uncomment test as part of #190
// {
// code: `
// exports.fooError = class FooError extends Error {
// constructor(error) {
// super(error);
// this.name = 'FooError';
// }
// };
// `,
// errors: [
// invalidNameError('fooError')
// ]
// },
{
code: `
exports.FooError = class FooError extends TypeError {
Expand Down

0 comments on commit cf3e22d

Please sign in to comment.