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

style: Use dedent for prettier multi-line template literals #242

Merged

Conversation

sudo-suhas
Copy link
Collaborator

This PR uses dedent for beautifying multi-line template literals:

const dedent = require('dedent');
// ...

// Before
console.log(`This is a multi-line
sentence`);

// After
console.log(dedent`
  This is a multi-line
  sentence
`)

@codecov
Copy link

codecov bot commented Aug 30, 2017

Codecov Report

Merging #242 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #242      +/-   ##
==========================================
+ Coverage   97.09%   97.15%   +0.06%     
==========================================
  Files          10       10              
  Lines         172      176       +4     
  Branches       26       26              
==========================================
+ Hits          167      171       +4     
  Misses          5        5
Impacted Files Coverage Δ
src/getConfig.js 97.14% <ø> (ø) ⬆️
src/index.js 88.88% <100%> (+1.01%) ⬆️
src/runScript.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3fa4f6d...af45ede. Read the comment docs.

okonet
okonet previously approved these changes Aug 30, 2017
Copy link
Collaborator

@okonet okonet left a comment

Choose a reason for hiding this comment

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

👍

@okonet
Copy link
Collaborator

okonet commented Aug 30, 2017

Do you mind waiting till I merge #141 and applying those changes again? I just spent an evening merging master into it and I think this PR will intro some conflicts again. 🙄

@sudo-suhas
Copy link
Collaborator Author

sudo-suhas commented Aug 30, 2017

Sure, no problem. Please ping here once that is done. I subscribed to that PR.

@sudo-suhas
Copy link
Collaborator Author

Invitation to join okonet/lint-staged from okonet

@okonet Thanks!

@okonet
Copy link
Collaborator

okonet commented Aug 30, 2017

@sudo-suhas it's a pleasure! 👍 Thanks for accepting. I don't mind more eyes and hands here :)

@okonet
Copy link
Collaborator

okonet commented Sep 4, 2017

@sudo-suhas do you need help with resolving conflicts in this one?

@sudo-suhas
Copy link
Collaborator Author

Nah.. I'll just discard my changes and start over.

@luftywiranda13
Copy link
Collaborator

@sudo-suhas do you use cmd or powershell on windows? I'm thinking about something to improve our cross-platform compatibility

@sudo-suhas
Copy link
Collaborator Author

sudo-suhas commented Sep 4, 2017

I actually use cmder. Helps me forget that I am on windows just a little bit 😆. But I can try out changes on cmd or powershell if needed.

@sudo-suhas
Copy link
Collaborator Author

I know this is less important but I figured since the PR was open and changes were simple, would be better to merge it in.

@sudo-suhas
Copy link
Collaborator Author

Rebasing and fixing conflicts.

}

will fix it and remove this message.
Unknown option \\"*.js\\" with value ['eslint --fix', 'git add'] was found in the config root.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way to keep this indentation of 2 spaces?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is possible if we keep a header text:

const message = dedent`
      WARNING
        Unknown option ${chalk.bold(`"${option}"`)} with value ${chalk.bold(
          format(config[option], { inlineCharacterLimit: Number.POSITIVE_INFINITY })
        )} was found in the config root.

        You are probably trying to mix simple and advanced config formats. Adding

        ${chalk.bold(`"linters": {
          "${option}": ${JSON.stringify(config[option])}
        }`)}

        will fix it and remove this message.
    `

Dedent uses the min of indentation to strip. So we need relative indentation. What do you suggest?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we put 2 spaces on the first line:

const message = dedent`  Unknown option ${chalk.bold(`"${option}"`)} with value ${chalk.bold(
          format(config[option], { inlineCharacterLimit: Number.POSITIVE_INFINITY })
        )} was found in the config root.

        You are probably trying to mix simple and advanced config formats. Adding

        ${chalk.bold(`"linters": {
          "${option}": ${JSON.stringify(config[option])}
        }`)}

        will fix it and remove this message.
    `

Copy link
Collaborator

Choose a reason for hiding this comment

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

Although it doesn't look very nice either...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about

const message = dedent`
  UNKNOWN OPTION
    Option ${chalk.bold(`"${option}"`)} with value ${chalk.bold(
      format(config[option], { inlineCharacterLimit: Number.POSITIVE_INFINITY })
    )} was found in the config root.

    You are probably trying to mix simple and advanced config formats. Adding

    ${chalk.bold(`"linters": {
      "${option}": ${JSON.stringify(config[option])}
    }`)}

    will fix it and remove this message.
`

Copy link
Collaborator

Choose a reason for hiding this comment

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

All caps are bad for readability. Also, I don't see a reason to have 2 titles. If dedent doesn't support our case, we should either not use it or add support to dedent. I don't want to compromise the UX in favor of better indented codebase.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay. That makes sense. I'll look into dedent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@okonet Small update, I made a PR to dedent which would allow us to specify default indent - dmnd/dedent#14.

Running lint-staged with the following config:
{
LOG Running lint-staged with the following config:
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's an odd indentation here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right, sorry I missed it. Can be fixed with this:

console.log(`Running lint-staged with the following config: \n${stringifyObject(config)}`)

Is this ok?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay with me!

src/index.js Outdated
Make sure you have created it. See https://github.com/okonet/lint-staged#readme.
console.error(dedent`
Could not parse lint-staged config.
Make sure you have created it. See https://github.com/okonet/lint-staged#readme.
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't it better if we set the link to https://github.com/okonet/lint-staged#configuration?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Configuration is better IMO. No need to search for it.

@okonet
Copy link
Collaborator

okonet commented Oct 11, 2017

Can this one be finalized, please?

@sudo-suhas
Copy link
Collaborator Author

I made a PR to dedent(dmnd/dedent#14) for our requirement but did not get a response yet.

@sudo-suhas
Copy link
Collaborator Author

@okonet I am not getting any response for the PR I made to dedent. We have a couple of options:

  • Don't use dedent for the section where we want some indentation.
  • Publish the package under a different name and allow for specifying indent.

What do you suggest?

@okonet
Copy link
Collaborator

okonet commented Nov 6, 2017

@sudo-suhas
Copy link
Collaborator Author

Yes @okonet that's what I meant by

Don't use dedent for the section where we want some indentation.

Will rebase and resolve conflicts.

@okonet okonet merged commit 0e40d2c into lint-staged:master Nov 8, 2017
@okonet
Copy link
Collaborator

okonet commented Nov 8, 2017

🍾

@sudo-suhas sudo-suhas deleted the style/dedent-template-literals branch November 8, 2017 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants