From 77824f681ea422fd6fdc346e451bdf96c165894e Mon Sep 17 00:00:00 2001 From: Matt Wang Date: Thu, 22 Jun 2023 21:58:35 -0700 Subject: [PATCH] Fix `declaration-block-no-redundant-longhand-properties` autofix for `grid-column` and `grid-row` (#6957) --- .changeset/wet-houses-warn.md | 5 +++++ .../__tests__/index.js | 12 ++++++++++ .../index.js | 22 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 .changeset/wet-houses-warn.md diff --git a/.changeset/wet-houses-warn.md b/.changeset/wet-houses-warn.md new file mode 100644 index 0000000000..1ce94b3382 --- /dev/null +++ b/.changeset/wet-houses-warn.md @@ -0,0 +1,5 @@ +--- +"stylelint": patch +--- + +Fixed: `declaration-block-no-redundant-longhand-properties` autofix for `grid-column` and `grid-row` diff --git a/lib/rules/declaration-block-no-redundant-longhand-properties/__tests__/index.js b/lib/rules/declaration-block-no-redundant-longhand-properties/__tests__/index.js index 7905102d86..7b77d3e305 100644 --- a/lib/rules/declaration-block-no-redundant-longhand-properties/__tests__/index.js +++ b/lib/rules/declaration-block-no-redundant-longhand-properties/__tests__/index.js @@ -206,6 +206,18 @@ testRule({ description: 'autofixer should not mangle css functions with comma separated values', message: messages.expected('transition'), }, + { + code: 'a { grid-column-start: 1; grid-column-end: 2; }', + fixed: 'a { grid-column: 1 / 2; }', + description: 'explicit grid-column test', + message: messages.expected('grid-column'), + }, + { + code: 'a { grid-row-start: 1; grid-row-end: 2; }', + fixed: 'a { grid-row: 1 / 2; }', + description: 'explicit grid-row test', + message: messages.expected('grid-row'), + }, { code: 'a { border-top-left-radius: 1em; border-top-right-radius: 2em; border-bottom-right-radius: 3em; border-bottom-left-radius: 4em; }', fixed: 'a { border-radius: 1em 2em 3em 4em; }', diff --git a/lib/rules/declaration-block-no-redundant-longhand-properties/index.js b/lib/rules/declaration-block-no-redundant-longhand-properties/index.js index 34d40d6665..1457f6ebb7 100644 --- a/lib/rules/declaration-block-no-redundant-longhand-properties/index.js +++ b/lib/rules/declaration-block-no-redundant-longhand-properties/index.js @@ -28,6 +28,28 @@ const meta = { /** @type {Map) => (string | undefined)>} */ const customResolvers = new Map([ + [ + 'grid-column', + (decls) => { + const start = decls.get('grid-column-start')?.value.trim(); + const end = decls.get('grid-column-end')?.value.trim(); + + if (!start || !end) return; + + return `${start} / ${end}`; + }, + ], + [ + 'grid-row', + (decls) => { + const start = decls.get('grid-row-start')?.value.trim(); + const end = decls.get('grid-row-end')?.value.trim(); + + if (!start || !end) return; + + return `${start} / ${end}`; + }, + ], [ 'grid-template', (decls) => {