Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kimtaejin3 committed Jul 16, 2024
1 parent 7be3ee5 commit 7a7429d
Showing 1 changed file with 34 additions and 21 deletions.
55 changes: 34 additions & 21 deletions lib/rules/jsx-closing-tag-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ const report = require('../util/report');
// ------------------------------------------------------------------------------

const messages = {
onOwnLine: 'Closing tag of a multiline JSX expression must be on its own line.',
onOwnLine:
'Closing tag of a multiline JSX expression must be on its own line.',
matchIndent: 'Expected closing tag to match indentation of opening.',
alignWithOpening: 'Expected closing tag to be aligned with the line containing the opening tag',
alignWithOpening:
'Expected closing tag to be aligned with the line containing the opening tag',
};

const defaultOption = 'tag-aligned';
Expand All @@ -41,22 +43,24 @@ module.exports = {
},
fixable: 'whitespace',
messages,
schema: [{
anyOf: [
{
enum: ['tag-aligned', 'line-aligned'],
},
{
type: 'object',
properties: {
location: {
enum: ['tag-aligned', 'line-aligned'],
schema: [
{
anyOf: [
{
enum: ['tag-aligned', 'line-aligned'],
},
{
type: 'object',
properties: {
location: {
enum: ['tag-aligned', 'line-aligned'],
},
},
additionalProperties: false,
},
additionalProperties: false,
},
],
}],
],
},
],
},

create(context) {
Expand All @@ -72,8 +76,8 @@ module.exports = {
}

function getIndentation(openingStartOfLine, opening) {
if (option === 'line-aligned') return openingStartOfLine.column + 1;
if (option === 'tag-aligned') return opening.loc.start.column + 1;
if (option === 'line-aligned') return openingStartOfLine.column;
if (option === 'tag-aligned') return opening.loc.start.column;
}

function handleClosingElement(node) {
Expand All @@ -95,11 +99,17 @@ module.exports = {
return;
}

if (opening.loc.start.column === node.loc.start.column && option === 'tag-aligned') {
if (
opening.loc.start.column === node.loc.start.column &&
option === 'tag-aligned'
) {
return;
}

if (openingStartOfLine.column === node.loc.start.column && option === 'line-aligned') {
if (
openingStartOfLine.column === node.loc.start.column &&
option === 'line-aligned'
) {
return;
}

Expand All @@ -111,7 +121,10 @@ module.exports = {
node,
loc: node.loc,
fix(fixer) {
const indent = repeat(' ', getIndentation(openingStartOfLine, opening));
const indent = repeat(
' ',
getIndentation(openingStartOfLine, opening)
);

if (astUtil.isNodeFirstInLine(context, node)) {
return fixer.replaceTextRange(
Expand Down

0 comments on commit 7a7429d

Please sign in to comment.