eslint-plugin-mgw-eslint-rules 2.3.19 → 2.3.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -44307,10 +44307,6 @@ var import_utils10 = __toESM(require_dist4());
44307
44307
  var NAMING_CONVENTIONS = ["camelCase", "strictCamelCase", "PascalCase", "StrictPascalCase", "snake_case", "UPPER_CASE", "kebab-case"];
44308
44308
  var ATTRIBUTE_CONVENTION_POSSIBLE_VALUES = [...NAMING_CONVENTIONS];
44309
44309
  var RULE_NAME8 = "template/attributes-naming-convention";
44310
- var ATTRIBUTE_DEFAULT_VALUES = {
44311
- id: "kebab-case",
44312
- class: "kebab-case"
44313
- };
44314
44310
  var conventionPatterns = {
44315
44311
  camelCase: /^[a-z][a-zA-Z0-9]*$/,
44316
44312
  strictCamelCase: /^(?!.*[A-Z]{2})[a-z][a-zA-Z0-9]*$/,
@@ -44354,12 +44350,26 @@ var rule8 = createRule8({
44354
44350
  enum: ATTRIBUTE_CONVENTION_POSSIBLE_VALUES
44355
44351
  },
44356
44352
  minItems: 1
44353
+ },
44354
+ {
44355
+ type: "object",
44356
+ properties: {
44357
+ pattern: {
44358
+ type: "array",
44359
+ items: {
44360
+ type: "string"
44361
+ },
44362
+ minItems: 1,
44363
+ //default: [],
44364
+ description: "Patterns regex to test"
44365
+ }
44366
+ },
44367
+ required: ["pattern"]
44357
44368
  }
44358
44369
  ]
44359
44370
  }
44360
44371
  }
44361
44372
  },
44362
- //required: ['conventions'],
44363
44373
  additionalProperties: false
44364
44374
  }
44365
44375
  ],
@@ -44367,44 +44377,50 @@ var rule8 = createRule8({
44367
44377
  },
44368
44378
  defaultOptions: [
44369
44379
  {
44370
- attributes: ATTRIBUTE_DEFAULT_VALUES
44380
+ id: "kebab-case",
44381
+ class: "kebab-case"
44371
44382
  }
44372
44383
  ],
44373
44384
  create(context, [options]) {
44374
44385
  const parserServices = (0, import_utils9.getTemplateParserServices)(context);
44375
- const attributesConfig = options.attributes || ATTRIBUTE_DEFAULT_VALUES;
44376
44386
  const listeAttributes = new Map(
44377
- Object.entries(attributesConfig).map(([a, n]) => {
44387
+ Object.entries(options).map(([a, n]) => {
44378
44388
  const listeNommage = typeof n === "string" ? [n] : n;
44379
- const nommageReg = listeNommage.map((c) => conventionPatterns[c]);
44380
- return [a, { noms: listeNommage.join(", "), regs: nommageReg }];
44389
+ if (Array.isArray(listeNommage)) {
44390
+ const nommageReg = listeNommage.map((c) => conventionPatterns[c]);
44391
+ return [a, { noms: listeNommage.join(", "), regs: nommageReg }];
44392
+ }
44393
+ return [
44394
+ a,
44395
+ {
44396
+ noms: listeNommage.pattern.join(", "),
44397
+ regs: listeNommage.pattern.map((p) => new RegExp(p))
44398
+ }
44399
+ ];
44381
44400
  })
44382
44401
  );
44383
44402
  return {
44384
44403
  // Détecte les attributs dans les templates (parcours global élément (noeud) par élément)
44385
- //'Element[attributes]'(node: TmplAstElement) {
44386
- //// const attributes = node.attributes;
44387
- //// On va parcourir tous les attributs
44388
- //// for (const attr of attributes) {
44389
- // Parcours attribut par attribut
44390
- "Element$1 > TextAttribute"(node) {
44391
- console.log(node);
44392
- if (node.value) {
44393
- const attrNomme = listeAttributes.get(node.name);
44394
- if (attrNomme) {
44395
- const attributeValues = node.value.split(/\s+/);
44396
- for (const attrValue of attributeValues) {
44397
- if (!attrNomme.regs.some((pattern) => pattern.test(attrValue))) {
44398
- const loc = parserServices.convertNodeSourceSpanToLoc(node.sourceSpan);
44399
- context.report({
44400
- loc,
44401
- messageId: "invalidNaming",
44402
- data: {
44403
- attribute: node.name,
44404
- value: attrValue,
44405
- conventions: attrNomme.noms
44406
- }
44407
- });
44404
+ "Element[attributes]"(node) {
44405
+ const attributes = node.attributes;
44406
+ for (const attr of attributes) {
44407
+ if (attr.value) {
44408
+ const attrNomme = listeAttributes.get(attr.name);
44409
+ if (attrNomme) {
44410
+ const attributeValues = attr.value.split(/\s+/);
44411
+ for (const attrValue of attributeValues) {
44412
+ if (!attrNomme.regs.some((pattern) => pattern.test(attrValue))) {
44413
+ const loc = parserServices.convertNodeSourceSpanToLoc(node.sourceSpan);
44414
+ context.report({
44415
+ loc,
44416
+ messageId: "invalidNaming",
44417
+ data: {
44418
+ attribute: attr.name,
44419
+ value: attrValue,
44420
+ conventions: attrNomme.noms
44421
+ }
44422
+ });
44423
+ }
44408
44424
  }
44409
44425
  }
44410
44426
  }