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

only lint with prefer_interpolation_to_compose_strings when one using at least one string literal #735

Closed
jacehensley-wf opened this issue Jul 12, 2017 · 3 comments

Comments

@jacehensley-wf
Copy link

Hey there, I think I came across an issue with the prefer_interpolation_to_compose_strings lint. When combining two non-literal strings I still get the lint, it seems odd that I should create a new string literal just to combine two existing strings.

var str1 = 'Hello';
var str2 = 'World';

// This lints, but I wouldn't expect it to.
var str3 = str1 + str2;
@alexeieleusis
Copy link
Contributor

I agree with your point, but your example seems a bit artificial (given that you could have had just one constant from the beginning). In the instances where I have seen this, either string interpolation or using a stringbuffer result in more readable (or efficient) code. Does this example reflect the issue you had in your code? Can you provide a closer one if not?

@jacehensley-wf
Copy link
Author

This is pretty close to what we have in our code base:

var listOfStrings = [];
  
var baseString = 'base';
  
var values = [
  'value1',
  'value2',
  'value3',
  'value4',
  'value5',
  'value6',
];
  
for (var value in values) {
  listOfStrings.add(baseString + value);
}

pq added a commit that referenced this issue Nov 2, 2017
#735)

Allow concatentation of two non-literal strings in `prefer_interpolation_to_compose_strings`.

Fixes: #735
@pq
Copy link
Member

pq commented Nov 2, 2017

Thanks for the example @jacehensley-wf!

@pq pq closed this as completed in #832 Nov 2, 2017
pq added a commit that referenced this issue Nov 2, 2017
#735) (#832)

Allow concatentation of two non-literal strings in `prefer_interpolation_to_compose_strings`.

Fixes: #735
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

No branches or pull requests

3 participants