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

Add no-caller and no-eval mergers #227

Merged
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/rules/mergers.ts
@@ -1,7 +1,11 @@
import { mergeBanTypes } from "./mergers/ban-types";
import { mergeNoCaller } from "./mergers/no-caller";
import { mergeNoEval } from "./mergers/no-eval";
import { mergeNoUnnecessaryTypeAssertion } from "./mergers/no-unnecessary-type-assertion";

export const mergers = new Map([
["@typescript-eslint/ban-types", mergeBanTypes],
["@typescript-eslint/no-unnecessary-type-assertion", mergeNoUnnecessaryTypeAssertion],
["no-caller", mergeNoCaller],
["no-eval", mergeNoEval],
]);
6 changes: 6 additions & 0 deletions src/rules/mergers/no-caller.ts
@@ -0,0 +1,6 @@
import { RuleMerger } from "../merger";

export const mergeNoCaller: RuleMerger = () => {
// no-caller rule does not accept any options
return [];
};
28 changes: 28 additions & 0 deletions src/rules/mergers/no-eval.ts
@@ -0,0 +1,28 @@
import { RuleMerger } from "../merger";

export const mergeNoEval: RuleMerger = (existingOptions, newOptions) => {
if (existingOptions === undefined && newOptions === undefined) {
return [];
}

let allowIndirect = true;

for (const options of [existingOptions, newOptions]) {
if (
options === undefined ||
options.length === 0 ||
options[0].allowIndirect === undefined
) {
allowIndirect = false;
break;
}

allowIndirect = allowIndirect && options[0].allowIndirect;
}

return [
{
...(allowIndirect && { allowIndirect }),
},
];
};
9 changes: 9 additions & 0 deletions src/rules/mergers/tests/no-caller.test.ts
@@ -0,0 +1,9 @@
import { mergeNoCaller } from "../no-caller";

describe(mergeNoCaller, () => {
test("neither options existing", () => {
const result = mergeNoCaller(undefined, undefined);

expect(result).toEqual([]);
});
});
45 changes: 45 additions & 0 deletions src/rules/mergers/tests/no-eval.test.ts
@@ -0,0 +1,45 @@
import { mergeNoEval } from "../no-eval";

describe(mergeNoEval, () => {
test("neither options existing", () => {
const result = mergeNoEval(undefined, undefined);

expect(result).toEqual([]);
});

test("neither allowIndirect existing", () => {
const result = mergeNoEval([{}], [{}]);

expect(result).toEqual([{}]);
});

test("original allowIndirect existing", () => {
const result = mergeNoEval([{ allowIndirect: true }], [{}]);

expect(result).toEqual([{}]);
});

test("new allowIndirect existing", () => {
const result = mergeNoEval([{}], [{ allowIndirect: true }]);

expect(result).toEqual([{}]);
});

test("original allowIndirect is false but new allowIndirect is true", () => {
const result = mergeNoEval([{ allowIndirect: false }], [{ allowIndirect: true }]);

expect(result).toEqual([{}]);
});

test("original allowIndirect is true but new allowIndirect is false", () => {
const result = mergeNoEval([{ allowIndirect: true }], [{ allowIndirect: false }]);

expect(result).toEqual([{}]);
});

test("both allowIndirect are true", () => {
const result = mergeNoEval([{ allowIndirect: true }], [{ allowIndirect: true }]);

expect(result).toEqual([{ allowIndirect: true }]);
});
});