Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eslint-plugin): [keyword-spacing] prevent crash on no options #6073

Merged
merged 1 commit into from Nov 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/eslint-plugin/src/rules/keyword-spacing.ts
Expand Up @@ -25,7 +25,7 @@ export default util.createRule<Options, MessageIds>({
},
defaultOptions: [{}],

create(context) {
create(context, [{ after }]) {
const sourceCode = context.getSourceCode();
const baseRules = baseRule.create(context);
return {
Expand Down Expand Up @@ -58,7 +58,7 @@ export default util.createRule<Options, MessageIds>({
const punctuatorToken = sourceCode.getTokenAfter(typeToken)!;
const spacesBetweenTypeAndPunctuator =
punctuatorToken.range[0] - typeToken.range[1];
if (context.options[0].after && spacesBetweenTypeAndPunctuator === 0) {
if (after && spacesBetweenTypeAndPunctuator === 0) {
context.report({
loc: punctuatorToken.loc,
messageId: 'expectedBefore',
Expand All @@ -68,7 +68,7 @@ export default util.createRule<Options, MessageIds>({
},
});
}
if (!context.options[0].after && spacesBetweenTypeAndPunctuator > 0) {
if (!after && spacesBetweenTypeAndPunctuator > 0) {
context.report({
loc: punctuatorToken.loc,
messageId: 'unexpectedBefore',
Expand Down