Debian Codegraph @

eslint/plugin-fig-linter/rules/no-invalid-name.js

raw symbols SCIP
1 const INVALID_REGEXP = /(<|\[).*(>|\])/;
2
3 const ERROR_MESSAGE = `The prop contains invalid characters.
4 If you subcommand / option takes an argument takes an argument, Fig will automatically
5 display this when you add a name prop to the args object.`;
6
7 module.exports = {
8 meta: {
9 type: "problem",
10 },
11 create(context) {
12 return {
13 Property(node) {
14 if (node.key.name === "options" || node.key.name === "subcommand") {
15 if (node.value && node.value.type === "ArrayExpression") {
16 node.value.elements.forEach((element) => {
17 if (element.type !== "ObjectExpression") return;
18
19 // Look for the name property in the options object
20 const nameProp = element.properties.find(
21 (prop) => prop.key && prop.key.name === "name"
22 );
23
24 if (!nameProp) return;
25
26 // Case: The name value is a string (single value)
27 if (nameProp.value.type === "Literal") {
28 if (INVALID_REGEXP.test(nameProp.value.value)) {
29 context.report({
30 node: nameProp,
31 message: ERROR_MESSAGE,
32 });
33 }
34 }
35 // Case: The name value is a list of strings (array)
36 if (nameProp.value.type === "ArrayExpression") {
37 nameProp.value.elements.forEach((literal) => {
38 if (INVALID_REGEXP.test(nameProp.value.value)) {
39 context.report({
40 node: literal,
41 message: ERROR_MESSAGE,
42 });
43 }
44 });
45 }
46 });
47 }
48 }
49 },
50 };
51 },
52 };