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

Fix 11 lints in src/plugins/tabletools.js #1039

Merged
merged 1 commit into from
Jan 30, 2019
Merged

Fix 11 lints in src/plugins/tabletools.js #1039

merged 1 commit into from
Jan 30, 2019

Conversation

wincent
Copy link
Contributor

@wincent wincent commented Jan 30, 2019

src/plugins/tabletools.js
   53:5  error  Unexpected var, use let or const instead   no-var
  167:4  error  Unexpected var, use let or const instead   no-var
  196:4  error  Unexpected var, use let or const instead   no-var
  212:9  error  Unexpected var, use let or const instead   no-var
  320:8  error  Unexpected var, use let or const instead   no-var
  329:4  error  Unexpected var, use let or const instead   no-var
  370:8  error  Unexpected var, use let or const instead   no-var
  371:9  error  Unexpected var, use let or const instead   no-var
  591:8  error  Unexpected var, use let or const instead   no-var
  709:4  error  Unexpected var, use let or const instead   no-var
  803:8  error  'lang' is assigned a value but never used  no-unused-vars

lang is safe to remove because the last references to it look like they were removed in c2d3248 ("Remove ui-related code from plugins", 2015).

The others I changed to let or const as appropriate. This code leans too heavily on let semantics in general, because values are reassigned and accessed sometimes quite large distances away.

One particularly nasty case was a for (var i = 0, rows = ...). This rows var is initialized in the loop and then accessed quite a bit further down outside the loop. For that one I had to hoist the let rows higher up in the scope. This is a bit of a foot-gun, and I only caught it by testing.

Test plan: npm run dev && npm run test && npm run start and test demo
(specifically tables).

Related: #990

```
src/plugins/tabletools.js
   53:5  error  Unexpected var, use let or const instead   no-var
  167:4  error  Unexpected var, use let or const instead   no-var
  196:4  error  Unexpected var, use let or const instead   no-var
  212:9  error  Unexpected var, use let or const instead   no-var
  320:8  error  Unexpected var, use let or const instead   no-var
  329:4  error  Unexpected var, use let or const instead   no-var
  370:8  error  Unexpected var, use let or const instead   no-var
  371:9  error  Unexpected var, use let or const instead   no-var
  591:8  error  Unexpected var, use let or const instead   no-var
  709:4  error  Unexpected var, use let or const instead   no-var
  803:8  error  'lang' is assigned a value but never used  no-unused-vars
```

`lang` is safe to remove because the last references to it look like
they were removed in c2d3248 ("Remove
ui-related code from plugins", 2015).

The others I changed to `let` or `const` as appropriate. This code leans
too heavily on `let` semantics in general, because values are reassigned
and accessed sometimes quite large distances away.

One particularly nasty case was a `for (var i = 0, rows = ...)`. This
`rows` var is initialized in the loop and then accessed quite a bit
further down outside the loop. For that one I had to hoist the `let
rows` higher up in the scope. This is a bit of a foot-gun, and I only
caught it by testing.

Test plan: `npm run dev && npm run test && npm run start` and test demo
(specifically tables).

Related: #990
for (var i = 0, rows = map.length; i < rows; i++) {
for (var j = 0, cols = map[i].length; j < cols; j++) {
for (let i = 0, rows = map.length; i < rows; i++) {
for (let j = 0, cols = map[i].length; j < cols; j++) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note this cols doesn't suffer the same problem as rows in the line above. cols is only accessed in the loop condition and not outside of it.

@julien
Copy link
Contributor

julien commented Jan 30, 2019

Just started reviewing :)

:octocat: Sent from GH.

@julien julien merged commit e443e3b into liferay:2.x-develop Jan 30, 2019
@wincent wincent deleted the lint/n+27 branch January 30, 2019 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants