@graphql-eslint/eslint-plugin
Version:
GraphQL plugin for ESLint
97 lines (96 loc) • 2.99 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var no_case_insensitive_enum_values_duplicates_exports = {};
__export(no_case_insensitive_enum_values_duplicates_exports, {
rule: () => rule
});
module.exports = __toCommonJS(no_case_insensitive_enum_values_duplicates_exports);
var import_graphql = require("graphql");
var import_utils = require("../utils.js");
const rule = {
meta: {
type: "suggestion",
hasSuggestions: true,
docs: {
url: "https://the-guild.dev/graphql/eslint/rules/no-case-insensitive-enum-values-duplicates",
category: "Schema",
recommended: true,
description: "Disallow case-insensitive enum values duplicates.",
examples: [
{
title: "Incorrect",
code: (
/* GraphQL */
`
enum MyEnum {
Value
VALUE
ValuE
}
`
)
},
{
title: "Correct",
code: (
/* GraphQL */
`
enum MyEnum {
Value1
Value2
Value3
}
`
)
}
]
},
schema: []
},
create(context) {
const selector = [import_graphql.Kind.ENUM_TYPE_DEFINITION, import_graphql.Kind.ENUM_TYPE_EXTENSION].join(",");
return {
[selector](node) {
var _a;
const duplicates = (_a = node.values) == null ? void 0 : _a.filter(
(item, index, array) => array.findIndex((v) => v.name.value.toLowerCase() === item.name.value.toLowerCase()) !== index
);
for (const duplicate of duplicates || []) {
const enumName = duplicate.name.value;
context.report({
node: duplicate.name,
message: `Unexpected case-insensitive enum values duplicates for ${(0, import_utils.getNodeName)(
duplicate
)}`,
suggest: [
{
desc: `Remove \`${enumName}\` enum value`,
fix: (fixer) => fixer.remove(duplicate)
}
]
});
}
}
};
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
rule
});