Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dedent indents consistently #312

Merged
merged 12 commits into from
Jul 25, 2022
Merged

Conversation

mnaoumov
Copy link
Contributor

Fixes #311

@pjkaufman
Copy link
Collaborator

Do you mind explaining what is inconsistent about the use of dedent here?

@pjkaufman
Copy link
Collaborator

I think I understand now. Did the linter not undo the change you are referring to?

@pjkaufman
Copy link
Collaborator

If we are making this change, we need a way to enforce it via the linter or a config that works for several editors.

@mnaoumov
Copy link
Contributor Author

@pjkaufman no, linter doesn't touch those changes. eslint is not aware of dedent, so it can't change anything. I'm looking if we can write our own rules for eslint

@mnaoumov
Copy link
Contributor Author

@mnaoumov
Copy link
Contributor Author

@pjkaufman I configured the linter rule to have dedent strings consistent. Also worked around those hard-to-catch cases with deliberate trailing spaces

Copy link
Collaborator

@pjkaufman pjkaufman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I agree with removing blank lines or trailing space. Can we not use a setting on the rule to avoid the hacky solution?

Note that linter removes trailing spaces and blank lines. In case if they are essential use the following trick to preserve them

```js
const str = dedent`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels very hacky.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the source code of the plugin

https://github.com/sindresorhus/eslint-plugin-unicorn/blob/20e959ffadeca007697534f1ad58c45d29cfdb04/rules/template-indent.js#L72

They do unconditional trimming.

I'll send them a PR to make it configurable

But honestly invisible trailing spaces are difficult to read anyway. With this "hack" we improve code readability

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take a closer look later on today.

@mnaoumov
Copy link
Contributor Author

`,
after: dedent`
# H1
Line with trailing spaces and tabs.
Line with trailing spaces and tabs. ${''}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there should be a tab present here based on the text. But maybe that is incorrect.

@pjkaufman pjkaufman merged commit 2e52a80 into platers:master Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use dedent consistently
2 participants