spiegel-keyman/common/web/eslint-plugin-keyman/lib/rules/prohibit-unitTestEndpoints.js
Marc Durdin 5e4ca43b60 maint(common): add lint for unitTestEndpoints usage
This is a stop-gap for v19. See #16767 for groundwork for v20. Enable
one rule, to verify `unitTestEndpoints` is not used except in unit
tests.

Follows: #16605
See-also: #16767
Test-bot: skip
2026-10-09 10:41:01 +02:00

49 lines
No EOL
1.2 KiB
JavaScript

/*
* Keyman is copyright (C) SIL Global. MIT License.
*
* Created by mcdurdin on 2026-10-09
*
* Enforce restrictions on use of unitTestEndpoints -- only for use in
* unit tests
*/
// import { RuleDefinition } from "@eslint/core";
module.exports = /*: RuleDefinition*/ {
meta: {
type: "problem",
docs: {
description: "Do not use unitTestEndpoints except in unit tests",
},
schema: [], // no options
},
create: function (context) {
return {
// callback functions
"Identifier[name=/^unitTestEndpoints$/]"(node) {
if(node.parent?.type == 'PropertyDefinition' || node.parent?.type == 'VariableDeclarator') {
// These are valid places to have endpoints
} else if(node.parent?.type == 'MemberExpression') {
context.report({
node,
message: 'Use of `unitTestEndpoints` outside unit tests.',
});
} else {
context.report({
node,
message: 'Unexpected `unitTestEndpoints` -- context is unclear',
});
}
}
};
},
};
// const plugin = {
// rules: {
// "prohibit-unitTestEndpoints": rule
// }
// };
// module.exports = plugin;