//------------------------------------------------------------------------------
const astUtils = require("./utils/ast-utils");
-const lodash = require("lodash");
//------------------------------------------------------------------------------
// Helpers
return { multiline, minProperties, consistent };
}
+/**
+ * Checks if a value is an object.
+ * @param {any} value The value to check
+ * @returns {boolean} `true` if the value is an object, otherwise `false`
+ */
+function isObject(value) {
+ return typeof value === "object" && value !== null;
+}
+
+/**
+ * Checks if an option is a node-specific option
+ * @param {any} option The option to check
+ * @returns {boolean} `true` if the option is node-specific, otherwise `false`
+ */
+function isNodeSpecificOption(option) {
+ return isObject(option) || typeof option === "string";
+}
+
/**
* Normalizes a given option value.
* @param {string|Object|undefined} options An option value to parse.
* }} Normalized option object.
*/
function normalizeOptions(options) {
- const isNodeSpecificOption = lodash.overSome([lodash.isPlainObject, lodash.isString]);
-
- if (lodash.isPlainObject(options) && lodash.some(options, isNodeSpecificOption)) {
+ if (isObject(options) && Object.values(options).some(isNodeSpecificOption)) {
return {
ObjectExpression: normalizeOptionValue(options.ObjectExpression),
ObjectPattern: normalizeOptionValue(options.ObjectPattern),
type: "layout",
docs: {
- description: "enforce consistent line breaks inside braces",
+ description: "enforce consistent line breaks after opening and before closing braces",
category: "Stylistic Issues",
recommended: false,
url: "https://eslint.org/docs/rules/object-curly-newline"
}
]
}
- ]
+ ],
+
+ messages: {
+ unexpectedLinebreakBeforeClosingBrace: "Unexpected line break before this closing brace.",
+ unexpectedLinebreakAfterOpeningBrace: "Unexpected line break after this opening brace.",
+ expectedLinebreakBeforeClosingBrace: "Expected a line break before this closing brace.",
+ expectedLinebreakAfterOpeningBrace: "Expected a line break after this opening brace."
+ }
},
create(context) {
if (needsLineBreaks) {
if (astUtils.isTokenOnSameLine(openBrace, first)) {
context.report({
- message: "Expected a line break after this opening brace.",
+ messageId: "expectedLinebreakAfterOpeningBrace",
node,
- loc: openBrace.loc.start,
+ loc: openBrace.loc,
fix(fixer) {
if (hasCommentsFirstToken) {
return null;
}
if (astUtils.isTokenOnSameLine(last, closeBrace)) {
context.report({
- message: "Expected a line break before this closing brace.",
+ messageId: "expectedLinebreakBeforeClosingBrace",
node,
- loc: closeBrace.loc.start,
+ loc: closeBrace.loc,
fix(fixer) {
if (hasCommentsLastToken) {
return null;
(consistent && hasLineBreakBetweenOpenBraceAndFirst && !hasLineBreakBetweenCloseBraceAndLast)
) {
context.report({
- message: "Unexpected line break after this opening brace.",
+ messageId: "unexpectedLinebreakAfterOpeningBrace",
node,
- loc: openBrace.loc.start,
+ loc: openBrace.loc,
fix(fixer) {
if (hasCommentsFirstToken) {
return null;
(consistent && !hasLineBreakBetweenOpenBraceAndFirst && hasLineBreakBetweenCloseBraceAndLast)
) {
context.report({
- message: "Unexpected line break before this closing brace.",
+ messageId: "unexpectedLinebreakBeforeClosingBrace",
node,
- loc: closeBrace.loc.start,
+ loc: closeBrace.loc,
fix(fixer) {
if (hasCommentsLastToken) {
return null;