Skip to content

Commit

Permalink
Allow rule.create to return undefined (#1912)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Sep 21, 2022
1 parent 7c8abf5 commit 4b61c92
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion rules/filename-case.js
Expand Up @@ -147,7 +147,7 @@ const create = context => {
const filenameWithExtension = context.getPhysicalFilename();

if (filenameWithExtension === '<input>' || filenameWithExtension === '<text>') {
return {};
return;
}

return {
Expand Down
2 changes: 1 addition & 1 deletion rules/no-empty-file.js
Expand Up @@ -20,7 +20,7 @@ const create = context => {
const filename = context.getPhysicalFilename().toLowerCase();

if (!/\.(?:js|mjs|cjs|ts|mts|cts)$/.test(filename)) {
return {};
return;
}

return {
Expand Down
2 changes: 1 addition & 1 deletion rules/prefer-module.js
Expand Up @@ -218,7 +218,7 @@ function create(context) {
const filename = context.getFilename().toLowerCase();

if (filename.endsWith('.cjs')) {
return {};
return;
}

const sourceCode = context.getSourceCode();
Expand Down
2 changes: 1 addition & 1 deletion rules/string-content.js
Expand Up @@ -70,7 +70,7 @@ const create = context => {
const replacements = getReplacements(patterns);

if (replacements.length === 0) {
return {};
return;
}

return {
Expand Down
16 changes: 12 additions & 4 deletions rules/utils/rule.js
Expand Up @@ -71,10 +71,18 @@ function reportProblems(create) {
return create;
}

const wrapped = context => Object.fromEntries(
Object.entries(create(context))
.map(([selector, listener]) => [selector, reportListenerProblems(listener, context)]),
);
const wrapped = context => {
const listeners = create(context);

if (!listeners) {
return {};
}

return Object.fromEntries(
Object.entries(listeners)
.map(([selector, listener]) => [selector, reportListenerProblems(listener, context)]),
);
};

wrappedFunctions.add(wrapped);

Expand Down

0 comments on commit 4b61c92

Please sign in to comment.