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

new rule option request: max-len ignores strings #5805

Closed
ljharb opened this issue Apr 7, 2016 · 22 comments
Closed

new rule option request: max-len ignores strings #5805

ljharb opened this issue Apr 7, 2016 · 22 comments
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules

Comments

@ljharb
Copy link
Sponsor Contributor

ljharb commented Apr 7, 2016

Currently, max-len supports ignoreComments, ignoreUrls, etc. I'd like to request an additional option, ignoreStrings.

My rationale is the following:

  • strings are an atomic token, and it is a code smell to treat them as anything other than a single unbroken unit.
  • trivial changes in the string contents might necessitate the string being re-joined and re-broken, causing unnecessary diff churn
  • people use line length limits for many things, but i personally use them as a proxy for limiting line complexity - as such, length isn't actually what i care about.

This affects both inline strings as well as "require" paths and "import from" paths (and should apply to template literals as well as single/double-quoted strings)

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Apr 7, 2016
@platinumazure platinumazure added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Apr 7, 2016
@platinumazure
Copy link
Member

Sounds good to me, but let's see what the rest of the team thinks.

@jgautsch
Copy link

jgautsch commented Apr 8, 2016

I too would like this, and would be happy to take a crack at a PR.

@ilyavolodin
Copy link
Member

So to clarify, should this apply to every node of type Literal or should there be some exceptions?

@ljharb
Copy link
Sponsor Contributor Author

ljharb commented Apr 9, 2016

@ilyavolodin I was only thinking string and template literals - however, I'd be equally fine with the option being called ignoreLiterals, since if I happened to have a very long number or regex, i wouldn't want to have to split it across lines.

@nzakas
Copy link
Member

nzakas commented Apr 12, 2016

@eslint/eslint-team does anyone want to champion this?

@alberto
Copy link
Member

alberto commented Apr 12, 2016

What is the proposed behaviour here? Ignore the whole line if it contains a string, like ignoreUrls? Discount the length of the string from the line length?

@ljharb
Copy link
Sponsor Contributor Author

ljharb commented Apr 12, 2016

@alberto i'd be fine with either. discounting the length of the string seems most useful to me, however.

@adamreisnz
Copy link

I would like to single out template literal strings specifically for this kind of rule, rather than all strings in general. Usually, template strings will contain HTML which sometimes can be quite lengthy on one line.

@ljharb
Copy link
Sponsor Contributor Author

ljharb commented Jun 28, 2016

I'm fine with two options - ignoreTemplateLiterals and ignoreStringLiterals, or, ignoreLiterals with an array of options.

lencioni added a commit to airbnb/javascript that referenced this issue Aug 4, 2016
Broken and concatenated long strings are painful to work with and
produce less readable and searchable code. I think we should reverse
this rule.

Unfortunately, the max-len rule currently does not allow for this, but
there is currently a proposal to add an option to ESLint's max-len rule
that would allow for strings to be ignored.

  eslint/eslint#5805

There have also been discussions around performance of string
concatenation (#40), but I
don't think that is very relevant here so I removed the links to them.
lencioni added a commit to airbnb/javascript that referenced this issue Aug 4, 2016
Broken and concatenated long strings are painful to work with and
produce less readable and searchable code. I think we should reverse
this rule.

Unfortunately, the max-len rule currently does not allow for this, but
there is currently a proposal to add an option to ESLint's max-len rule
that would allow for strings to be ignored.

  eslint/eslint#5805

There have also been discussions around performance of string
concatenation (#40), but I
don't think that is very relevant here so I removed the links to them.
lencioni added a commit to airbnb/javascript that referenced this issue Aug 4, 2016
Broken and concatenated long strings are painful to work with and
produce less readable and searchable code. I think we should reverse
this rule.

Unfortunately, the max-len rule currently does not allow for this, but
there is currently a proposal to add an option to ESLint's max-len rule
that would allow for strings to be ignored.

  eslint/eslint#5805

There have also been discussions around performance of string
concatenation (#40), but I
don't think that is very relevant here so I removed the links to them.
@lencioni
Copy link
Contributor

lencioni commented Aug 4, 2016

The Airbnb JavaScript style guide now recommends not breaking and concatenating long strings. https://github.com/airbnb/javascript#strings--line-length

@platinumazure platinumazure added needs info Not enough information has been provided to triage this issue and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Aug 4, 2016
@eslintbot
Copy link

eslintbot commented Aug 4, 2016

Hi @ljharb, thanks for the issue. It looks like there's not enough information for us to know how to help you.

Requesting a new rule? Please see Proposing a New Rule for instructions.

@platinumazure
Copy link
Member

platinumazure commented Aug 4, 2016

Can someone please put together a concrete proposal using the "Proposing a Rule Change" instructions above, which answers all of the open questions? If someone can get that put together, I'm willing to champion.

Open questions:

  • Should strings and template literals be configurable independently, and if so, how should those options look?
  • Should we discount the length of the string from the offending line (but still check that all tokens before the last literal are within the max-len limits)? Or just not report the whole line?
    • What is done for ignoreUrls? Should we follow that behavior? Why or why not?

If we can get consensus around these questions, I think we can move forward with this.

@ljharb
Copy link
Sponsor Contributor Author

ljharb commented Aug 4, 2016

  • Yes, because I don't wish to distinguish between template literals and other string literals - although I don't object to new rule option request: max-len ignores strings #5805 (comment), and configurability is a good thing.
  • Personally I think the length of the string should be discounted from the line entirely, but in reality it should be identical to what "ignoreUrls" does.

I'll write what you're requesting now.

@ljharb
Copy link
Sponsor Contributor Author

ljharb commented Aug 10, 2016

What version of ESLint are you using?
any

What rule do you want to change?
max-len - add an option for ignoreStringLiterals, and an option for ignoreTemplateLiterals.

What code should be flagged as incorrect with this change?

// these warn
// eslint max-len: [2, 10, { "ignoreStringLiterals": false, "ignoreTemplateLiterals": false }]
a = 'too long';
a = `too long`;


// this is correct
// eslint max-len: [2, 10, { "ignoreStringLiterals": true }]
a = 'too long';
// eslint max-len: [2, 10, { "ignoreTemplateLiterals": true }]
a = `too long`;

What happens when the rule is applied to this code now?
It warns on the "this is correct" options.

Note: just like "ignoreURLs", both of these options should cause the entire line on which the literals appear to be ignored for the max-len rule.

@platinumazure
Copy link
Member

I will champion @ljharb's proposal.

@vitorbal
Copy link
Member

👍 from me.

@ilyavolodin
Copy link
Member

👍

@platinumazure platinumazure added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed needs info Not enough information has been provided to triage this issue labels Aug 11, 2016
@platinumazure platinumazure self-assigned this Aug 11, 2016
@distributedlock
Copy link

distributedlock commented Aug 22, 2016

This would help a lot. 👍

@kaicataldo
Copy link
Member

👍

@mysticatea mysticatea added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Aug 22, 2016
@platinumazure
Copy link
Member

@ljharb This is now accepted. Were you thinking of writing a PR?

@ljharb
Copy link
Sponsor Contributor Author

ljharb commented Aug 26, 2016

If nobody gets to it first, definitely! Just need to find the time :-)

@stephenhuh
Copy link

stephenhuh commented Sep 6, 2016

nice job @ljharb , can't wait to see this merged.

ljharb added a commit to ljharb/eslint that referenced this issue Sep 6, 2016
hibearpanda pushed a commit to 15Prospects/javascript that referenced this issue Jan 22, 2017
Broken and concatenated long strings are painful to work with and
produce less readable and searchable code. I think we should reverse
this rule.

Unfortunately, the max-len rule currently does not allow for this, but
there is currently a proposal to add an option to ESLint's max-len rule
that would allow for strings to be ignored.

  eslint/eslint#5805

There have also been discussions around performance of string
concatenation (airbnb#40), but I
don't think that is very relevant here so I removed the links to them.
jaylaw81 pushed a commit to appirio-digital/ads-best-practices that referenced this issue Sep 19, 2017
Broken and concatenated long strings are painful to work with and
produce less readable and searchable code. I think we should reverse
this rule.

Unfortunately, the max-len rule currently does not allow for this, but
there is currently a proposal to add an option to ESLint's max-len rule
that would allow for strings to be ignored.

  eslint/eslint#5805

There have also been discussions around performance of string
concatenation (airbnb#40), but I
don't think that is very relevant here so I removed the links to them.
jaylaw81 pushed a commit to appirio-digital/ads-best-practices that referenced this issue Sep 19, 2017
sensiblegame added a commit to sensiblegame/React-BNB that referenced this issue Oct 23, 2017
Broken and concatenated long strings are painful to work with and
produce less readable and searchable code. I think we should reverse
this rule.

Unfortunately, the max-len rule currently does not allow for this, but
there is currently a proposal to add an option to ESLint's max-len rule
that would allow for strings to be ignored.

  eslint/eslint#5805

There have also been discussions around performance of string
concatenation (airbnb/javascript#40), but I
don't think that is very relevant here so I removed the links to them.
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests