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

lint: wrap js strings (in src/) #548

Closed
jorgeorpinel opened this issue Aug 11, 2019 · 23 comments · Fixed by #715 or #755
Closed

lint: wrap js strings (in src/) #548

jorgeorpinel opened this issue Aug 11, 2019 · 23 comments · Fixed by #715 or #755
Assignees
Labels
A: docs Area: user documentation (gatsby-theme-iterative) type: enhancement Something is not clear, small updates, improvement suggestions website: eng-doc DEPRECATED JS engine for /doc

Comments

@jorgeorpinel
Copy link
Contributor

jorgeorpinel commented Aug 11, 2019

UPDATE: See #548 (comment).


OUTDATED:

String values in JavaScript files are currently not automatically wrapped to 80 chars by the pre-commit hook that runs pretty-quick, like all other lines of code. If possible, have the linter do this. E.g.

const strVar  = "Really long string going over 80 characters. Blah blah blah blah blah blah blah"
let templateLit = `
Another long text
Including lines that go over 80 chars. Blah blah blah blah blah blah blah blah blah blah blah blah
`

This would be pretty useful to make sure the glossary.js strings are properly wrapped, for example.

@jorgeorpinel jorgeorpinel added the type: enhancement Something is not clear, small updates, improvement suggestions label Aug 11, 2019
@shcheklein shcheklein added A: docs Area: user documentation (gatsby-theme-iterative) website: eng-doc DEPRECATED JS engine for /doc labels Aug 11, 2019
@shcheklein

This comment has been minimized.

@jorgeorpinel
Copy link
Contributor Author

jorgeorpinel commented Aug 11, 2019

I'm unable to do this in the Prettier playground. (Wrap at 40 chars in the linked example)

@algomaster99
Copy link
Contributor

@jorgeorpinel @shcheklein they haven't addressed this issue yet. prettier/prettier#4123 I think we need to manually wrap strings. 😕

@jorgeorpinel

This comment has been minimized.

@algomaster99

This comment has been minimized.

@jorgeorpinel jorgeorpinel added the status: research Writing concrete steps for the issue label Oct 19, 2019
@jorgeorpinel
Copy link
Contributor Author

jorgeorpinel commented Oct 19, 2019

If you have time now to research this one @algomaster99 (or anyone out there) it would be nice, that way we can confirm or remove the issue.

Keep in mind we're also using ESlint. This rule can probably address the concern: https://eslint.org/docs/rules/max-len

@jorgeorpinel jorgeorpinel added good first issue Good for newcomers help wanted Contributors especially welcome labels Oct 19, 2019
@algomaster99
Copy link
Contributor

@jorgeorpinel ESLint cannot fix this but it can do detect when the line goes above 80 characters. We just need to put "max-len": [ "error", { "ignoreStrings": false } ], in configuration.

@jorgeorpinel jorgeorpinel removed the good first issue Good for newcomers label Oct 20, 2019
@jorgeorpinel
Copy link
Contributor Author

jorgeorpinel commented Oct 20, 2019

Yeah, boo. I tried that rule with eslink --fix src but it doesn't fix this type of problem, it seems.

Well, let's make the issue to fix all the problems it currently reports, at least, and add the ESLint rule anyway for the future. Problems:

$ eslint src                
yarn run v1.19.1
$ /.../dvc.org/node_modules/.bin/eslint src

/.../dvc.org/src/Diagram/index.js
  209:1  error  This line has a length of 83. Maximum allowed is 80  max-len

✔️ /.../dvc.org/src/Documentation/HeadInjector.js
  10:1  error  This line has a length of 101. Maximum allowed is 80  max-len
  14:1  error  This line has a length of 87. Maximum allowed is 80   max-len
  18:1  error  This line has a length of 95. Maximum allowed is 80   max-len
  22:1  error  This line has a length of 85. Maximum allowed is 80   max-len

✔️ /.../dvc.org/src/Documentation/Markdown/Markdown.js
  58:1  error  This line has a length of 349. Maximum allowed is 80  max-len

✔️ /.../dvc.org/src/Documentation/SidebarMenu/helper.test.js
  260:1  error  This line has a length of 82. Maximum allowed is 80  max-len

✔️ /.../dvc.org/src/Documentation/glossary.js
  37:1  error  This line has a length of 83. Maximum allowed is 80  max-len
  46:1  error  This line has a length of 81. Maximum allowed is 80  max-len
  71:1  error  This line has a length of 81. Maximum allowed is 80  max-len

✔️ /.../dvc.org/src/DownloadButton/index.js
  19:1  error  This line has a length of 91. Maximum allowed is 80   max-len
  23:1  error  This line has a length of 91. Maximum allowed is 80   max-len
  27:1  error  This line has a length of 97. Maximum allowed is 80   max-len
  31:1  error  This line has a length of 100. Maximum allowed is 80  max-len

/.../dvc.org/src/LandingHero/index.js
  145:1  error  This line has a length of 83. Maximum allowed is 80  max-len
  159:1  error  This line has a length of 83. Maximum allowed is 80  max-len
  270:1  error  This line has a length of 83. Maximum allowed is 80  max-len
  294:1  error  This line has a length of 83. Maximum allowed is 80  max-len

/.../dvc.org/src/Subscribe/index.js
  32:1  error  This line has a length of 83. Maximum allowed is 80  max-len
  48:1  error  This line has a length of 83. Maximum allowed is 80  max-len

✔️ /.../dvc.org/src/SubscribeForm/index.js
   8:1  error  This line has a length of 112. Maximum allowed is 80  max-len
  25:1  error  This line has a length of 116. Maximum allowed is 80  max-len

✔️ /.../dvc.org/src/Video/index.js
  78:1  error  This line has a length of 102. Maximum allowed is 80  max-len

/.../dvc.org/src/styles.js
  78:1  error  This line has a length of 83. Maximum allowed is 80  max-len

✖ 24 problems (24 errors, 0 warnings)

UPDATE: I checked with ✔️ the ones fixed so far in #715 up to my last revision.

@jorgeorpinel jorgeorpinel added the good first issue Good for newcomers label Oct 20, 2019
@algomaster99
Copy link
Contributor

@jorgeorpinel yeah, we have to do it manually first. Once it is fixed, eslint would make sure this error is not there.

@jorgeorpinel jorgeorpinel removed help wanted Contributors especially welcome status: research Writing concrete steps for the issue labels Oct 21, 2019
@jorgeorpinel jorgeorpinel changed the title lint: wrap js strings lint: wrap js strings (in src/) Oct 21, 2019
@jorgeorpinel jorgeorpinel changed the title lint: wrap js strings (in src/) lint: wrap js strings (in root and src/) Oct 21, 2019
@jorgeorpinel jorgeorpinel changed the title lint: wrap js strings (in root and src/) lint: wrap js strings (src/) Oct 21, 2019
@jorgeorpinel jorgeorpinel changed the title lint: wrap js strings (src/) lint: wrap js strings (in src/) Oct 21, 2019
@shcheklein shcheklein reopened this Oct 29, 2019
@shcheklein
Copy link
Member

@algomaster99 I think the PR that was merge broke the style of the dvc.org for a few hours:

Screen Shot 2019-10-28 at 9 15 58 PM

we don't have a QA team and we trust that engineers do some basic testing. Please, review it again and run it locally every time before we merge or specify [WIP].

I've reverted the changes. Please create a new PR to handle this.

@jorgeorpinel thanks for noticing this!

@algomaster99
Copy link
Contributor

@shcheklein
Sorry, this happened. But I assure it is a very quick fix.

This happened because of writing URLs in src/Documentation/HeadInjector.js.
I broke:

<script
  type="text/javascript"
  src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn/docsearch.min.js"
/>

into this:

<script
  type="text/javascript"
  src={`
    https://cdn.jsdelivr.net/npm/
    [email protected]/dist/cdn/docsearch.min.js
  `}
/>

The solution could be to:

  1. Make use of template literals since we already added to ignore it in .eslintrc.
<script
    type="text/javascript"
    src={`https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn/docsearch.min.js`}
/>
  1. Or make use of // eslint-disable-next-line exactly what we did for that long svg tag.
<script
  type="text/javascript"
  // eslint-disable-next-line max-len
  src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn/docsearch.min.js"
/>

https://github.com/iterative/dvc.org/pull/715/files#diff-b1d807de8934c24309015d3c1ea18882R58-R59

@shcheklein
Copy link
Member

@algomaster99 using some special syntax for every URL looks unacceptable to me. Could you please google some discussion how do people deal with this? The most interesting thing here is that prettier broke the code. This looks like a bug to me to be honest.

@algomaster99
Copy link
Contributor

algomaster99 commented Oct 29, 2019

@shcheklein Okay, I got it. We could again edit "max-len": ["error", { "ignoreTemplateLiterals": true }], to ignore URLs too.
Something like this:

"max-len": ["error", { "ignoreTemplateLiterals": true, "ignoreUrls": true }],

@shcheklein
Copy link
Member

k, looks reasonable

@algomaster99

This comment has been minimized.

@shcheklein
Copy link
Member

@algomaster99 but they are templates, right?

@algomaster99
Copy link
Contributor

@shcheklein Sorry, my bad! Didn't notice. 🤦‍♂️

@jorgeorpinel
Copy link
Contributor Author

jorgeorpinel commented Oct 29, 2019

Did we ever find a full reference of what exactly plugin:prettier/recommended does in the ESLint config? Just curious.

From #715 (comment).

@algomaster99
Copy link
Contributor

@shcheklein
Copy link
Member

@algomaster99 I think it does not answer the question :) Not very helpful link - no information whatsoever.

@algomaster99
Copy link
Contributor

@jorgeorpinel @shcheklein

So there are two packages installed in our project called - eslint-config-prettier and eslint-plugin-prettier.

  1. eslint-config-prettier - Its purpose is to switch off all rules which may conflict with prettier configuration. https://github.com/prettier/eslint-config-prettier#special-rules
  2. eslint-plugin-prettier - Whenever you run eslint, this plugin makes sure it will run prettier too. For example, let's say we leave out a semi-colon in our code. Running eslint will return the following log.
    Screenshot from 2019-10-27 12-40-30

Now to include these two configurations silmuntaneously, we simply need to add one line in .eslintrc.json

{
  "extends": [
    "plugin:prettier/recommended"
  ]
}

@shcheklein
Copy link
Member

@algomaster99 I would clarify though that special rules set is not the full set of rules that are being applied. Probably, this is the full list https://github.com/prettier/eslint-config-prettier/blob/master/index.js . May be there is some other logic around that changes the effective list.

@algomaster99
Copy link
Contributor

@shcheklein yes, eslint-config-prettier turns off all the rules they have listen in the README . We just switched on max-len for our purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: docs Area: user documentation (gatsby-theme-iterative) type: enhancement Something is not clear, small updates, improvement suggestions website: eng-doc DEPRECATED JS engine for /doc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants