Valeriy Kuzmin,
Lilt, 2020
// @typescript-eslint/explicit-module-boundary-types
// no error !!!
module.exports.myFunc = (arg1: number, arg2,
arg3: boolean) => {
...
}
// an error
export const myFunc = (arg1: number, arg2,
arg3: boolean) => {
...
}
JS
TS
Rule 1: use TS & Eslint
Rule 2: boundaries
Rule 3: no problematic code
Time
a + b
Binarry expression
Operator +
Left:
variable a
Right:
variable b
module.exports = 456;
AssignmentExpression(node) {
try {
if (
_.get(node, "left.object.name") === "module" ||
_.get(node, "left.object.property.name") === "exports" ||
_.get(node, "left.object.name") === "exports" ||
_.get(node, "left.name") === "exports"
) {
context.report({ messageId: "noModuleInTsError", node });
}
} catch (error) {
context.report({
node,
messageId: "unknownError"
});
}
}
};
Apparently our version of parser is a bit buggy, hence _.get
.eslintrc.js:
"local-rules/no-module-in-ts": 2
eslint-local-rules.js:
"no-module-in-ts": require("./libs/eslint/rules/no-module-in-ts").default
My personal CTA: no rule exceptions in .eslintrc, only inside files (item 2 in the form)
Questions?