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

fluent-chaining rule error for chained methods with array access #54

Open
yokuze opened this issue Feb 17, 2021 · 1 comment
Open

fluent-chaining rule error for chained methods with array access #54

yokuze opened this issue Feb 17, 2021 · 1 comment
Assignees

Comments

@yokuze
Copy link
Contributor

yokuze commented Feb 17, 2021

The fluent-chaining rule emits this error message:

Identifier "undefined" should be on a new line

for code that contains both chained method calls and array access. For example:

url = url
   // Remove any query string:
   .split('?')[0]
   // Remove any hash:
   .split('#')[0];

The above code strips the query string and hash from a URL. Both of the [0] array access statements trigger an error for the fluent-chaining rule with the error message "Identifier "undefined" should be on a new line".

True, we could rewrite this as:

// Remove any query string:
url = url.split('?')[0];
// Remove any hash:
url = url.split('#')[0];

but personally I like the simplicity of the chained method calls, particularly if there were more needed.

Should we support this pattern?

If so, we need to modify the fluent-chaining rule to support this case.

If not, we probably need to fix the error message so that it doesn't print "undefined" where it seems it should print some identifier name. Additionally, when you apply ESLint's suggested auto-fix, you get:

url = url
   // Remove any query string
   .split('?')
   .0]

which removes one of the array access statement's braces and creates invalid JavaScript.

@jthomerson
Copy link
Member

@yokuze I agree we should support this usecase in our rule

@pbredenberg pbredenberg self-assigned this Mar 28, 2024
pbredenberg added a commit to pbredenberg/eslint-plugin-silvermine that referenced this issue May 10, 2024
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