Skip to content

Commit

Permalink
Fix indentation with tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
renatho committed May 7, 2021
1 parent 65528e2 commit ed1df26
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/alignTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const space = (len) => {
return ''.padStart(len, ' ');
};

const alignTransform = (tags) => {
const alignTransform = (tags, indent) => {
let intoTags = false;
let width;

Expand Down Expand Up @@ -120,7 +120,7 @@ const alignTransform = (tags) => {

// dangling '*/'
if (tokens.end === Markers.end && isEmpty) {
tokens.start = space(width.start + 1);
tokens.start = indent + ' ';

return {
...line,
Expand All @@ -131,16 +131,16 @@ const alignTransform = (tags) => {
/* eslint-disable indent */
switch (tokens.delimiter) {
case Markers.start:
tokens.start = space(width.start);
tokens.start = indent;
break;
case Markers.delim:
tokens.start = space(width.start + 1);
tokens.start = indent + ' ';
break;
default:
tokens.delimiter = '';

// compensate delimiter
tokens.start = space(width.start + 2);
tokens.start = indent + ' ';
}
/* eslint-enable */

Expand Down
3 changes: 1 addition & 2 deletions src/rules/checkLineAlignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import iterateJsdoc from '../iterateJsdoc';

const {
flow: commentFlow,
indent: commentIndent,
} = transforms;

const checkNotAlignedPerTag = (utils, tag) => {
Expand Down Expand Up @@ -105,7 +104,7 @@ const checkAlignment = ({
tags,
utils,
}) => {
const transform = commentFlow(alignTransform(tags), commentIndent(indent.length));
const transform = commentFlow(alignTransform(tags, indent));
const transformedJsdoc = transform(jsdoc);

const comment = '/*' + jsdocNode.value + '*/';
Expand Down
47 changes: 47 additions & 0 deletions test/rules/assertions/checkLineAlignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,37 @@ export default {
const fn = ( lorem, sit ) => {}
`,
},
/* eslint-disable no-tabs */
{
code: `
/**
* With tabs.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
`,
errors: [
{
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
],
options: [
'always',
],
output: `
/**
* With tabs.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
`,
},
/* eslint-enable no-tabs */
{
code: `
/**
Expand Down Expand Up @@ -845,6 +876,22 @@ export default {
'always',
],
},
/* eslint-disable no-tabs */
{
code: `
/**
* With tabs.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
`,
options: [
'always',
],
},
/* eslint-enable no-tabs */
{
code: `
/**
Expand Down

0 comments on commit ed1df26

Please sign in to comment.