@graphql-eslint/eslint-plugin
Version:
GraphQL plugin for ESLint
103 lines (102 loc) • 3.1 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: !0 });
}, __copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function")
for (let key of __getOwnPropNames(from))
!__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: !0 }), mod);
var description_style_exports = {};
__export(description_style_exports, {
rule: () => rule
});
module.exports = __toCommonJS(description_style_exports);
var import_utils = require("../utils.js");
const schema = {
type: "array",
maxItems: 1,
items: {
type: "object",
additionalProperties: !1,
minProperties: 1,
properties: {
style: {
enum: ["block", "inline"],
default: "block"
}
}
}
}, rule = {
meta: {
type: "suggestion",
hasSuggestions: !0,
docs: {
examples: [
{
title: "Incorrect",
usage: [{ style: "inline" }],
code: (
/* GraphQL */
`
""" Description """
type someTypeName {
# ...
}
`
)
},
{
title: "Correct",
usage: [{ style: "inline" }],
code: (
/* GraphQL */
`
" Description "
type someTypeName {
# ...
}
`
)
}
],
description: "Require all comments to follow the same style (either block or inline).",
category: "Schema",
url: "https://the-guild.dev/graphql/eslint/rules/description-style",
recommended: !0
},
schema
},
create(context) {
const { style = "block" } = context.options[0] || {}, isBlock = style === "block";
return {
[`.description[type=StringValue][block!=${isBlock}]`](node) {
context.report({
loc: isBlock ? node.loc : node.loc.start,
message: `Unexpected ${isBlock ? "inline" : "block"} description for ${(0, import_utils.getNodeName)(
node.parent
)}`,
suggest: [
{
desc: `Change to ${isBlock ? "block" : "inline"} style description`,
fix(fixer) {
const originalText = context.getSourceCode().getText(node), newText = isBlock ? originalText.replace(/(^")|("$)/g, '"""') : originalText.replace(/(^""")|("""$)/g, '"').replace(/\s+/g, " ");
return fixer.replaceText(node, newText);
}
}
]
});
}
};
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
rule
});