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

[eslint] Add recommended rules #1253

Closed
dayo09 opened this issue Sep 2, 2022 · 9 comments
Closed

[eslint] Add recommended rules #1253

dayo09 opened this issue Sep 2, 2022 · 9 comments

Comments

@dayo09
Copy link
Contributor

dayo09 commented Sep 2, 2022

What?

To enables eslint:recommended extends, let's first remove some violations by adding simple recommended rules.

@dayo09 dayo09 changed the title [lint] Remove unnecessary semicolons [eslint] Add recommended rules Sep 2, 2022
@dayo09
Copy link
Contributor Author

dayo09 commented Sep 6, 2022

Remaining errors : 71 problems

After #1254, #1255 is merged,


/home/dayo/git/ONE-vscode/src/Backend/Compiler.ts
  80:17  error  'toolchainType' is defined but never used  no-unused-vars
  80:40  error  'start' is defined but never used          no-unused-vars
  80:55  error  'count' is defined but never used          no-unused-vars
  84:26  error  'toolchainType' is defined but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/Backend/Executor.ts
  53:16  error  '_modelPath' is defined but never used  no-unused-vars
  53:36  error  '_options' is defined but never used    no-unused-vars

/home/dayo/git/ONE-vscode/src/Backend/Toolchain.ts
  61:7  error  'cfg' is defined but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/CfgEditor/CfgEditorPanel.ts
   76:7   error  '_token' is defined but never used            no-unused-vars
  146:11  error  Unexpected lexical declaration in case block  no-case-declarations
  152:11  error  Unexpected lexical declaration in case block  no-case-declarations
  176:39  error  'e' is defined but never used                 no-unused-vars

/home/dayo/git/ONE-vscode/src/CircleGraph/CircleGraph.ts
  87:38  error  'e' is defined but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/CircleGraph/CircleGraphCtrl.ts
  345:21  error  'err' is defined but never used   no-unused-vars
  366:26  error  Unnecessary escape character: \%  no-useless-escape

/home/dayo/git/ONE-vscode/src/CircleGraph/CircleViewer.ts
  127:24  error  'openContext' is defined but never used  no-unused-vars
  128:7   error  '_token' is defined but never used       no-unused-vars
  142:7   error  '_token' is defined but never used       no-unused-vars

/home/dayo/git/ONE-vscode/src/Execute/DeviceViewProvider.ts
   24:9   error  'Balloon' is defined but never used  no-unused-vars
  153:44  error  'reject' is defined but never used   no-unused-vars

/home/dayo/git/ONE-vscode/src/Job/Job.ts
  45:18  error  'Job' is already defined  no-redeclare

/home/dayo/git/ONE-vscode/src/Job/ToolRunner.ts
  23:7  error  'path' is assigned a value but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/Jsontracer/JsonTracerViewerPanel.ts
   72:7   error  '_token' is defined but never used  no-unused-vars
  117:39  error  'e' is defined but never used       no-unused-vars

/home/dayo/git/ONE-vscode/src/Mondrian/MondrianEditor.ts
  43:7  error  '_token' is defined but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/PartEditor/PartEditor.ts
  101:9   error  'e' is defined but never used                                              no-unused-vars
  289:24  error  'err' is defined but never used                                            no-unused-vars
  331:17  error  Do not access Object.prototype method 'hasOwnProperty' from target object  no-prototype-builtins
  334:17  error  Do not access Object.prototype method 'hasOwnProperty' from target object  no-prototype-builtins
  354:39  error  'tensors' is defined but never used                                        no-unused-vars
  390:7   error  'token' is defined but never used                                          no-unused-vars
  414:26  error  Unnecessary escape character: \%                                           no-useless-escape

/home/dayo/git/ONE-vscode/src/PartEditor/PartGraphSelector.ts
  208:38  error  'e' is defined but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/Tests/Backend/Compiler.test.ts
  24:15  error  'compiler' is assigned a value but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/Tests/Backend/Executor.test.ts
  24:15  error  'executor' is assigned a value but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/Tests/Backend/Toolchain.test.ts
  26:15  error  'toolchain' is assigned a value but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/Tests/Backend/ToolchainImpl/DebianToolchain.test.ts
  18:9  error  'PackageInfo' is defined but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/Tests/Execute/Device.test.ts
  40:15  error  'testDevice' is assigned a value but never used  no-unused-vars
  64:15  error  'tizenTV' is assigned a value but never used     no-unused-vars
  88:15  error  'hostPC' is assigned a value but never used      no-unused-vars

/home/dayo/git/ONE-vscode/src/Tests/Execute/DeviceViewProvider.test.ts
   19:9   error  'globalExecutorArray' is defined but never used  no-unused-vars
   20:9   error  'ExecutorBase' is defined but never used         no-unused-vars
  104:52  error  '_provider' is defined but never used            no-unused-vars
  115:52  error  '_provider' is defined but never used            no-unused-vars
  133:52  error  '_provider' is defined but never used            no-unused-vars

/home/dayo/git/ONE-vscode/src/Tests/Job/ToolRunner.test.ts
   18:9   error  'join' is defined but never used               no-unused-vars
  119:13  error  'finished' is assigned a value but never used  no-unused-vars
  131:20  error  'exitcode' is defined but never used           no-unused-vars
  158:20  error  'exitcode' is defined but never used           no-unused-vars

/home/dayo/git/ONE-vscode/src/Tests/OneExplorer/ArtifactLocator.test.ts
  179:32  error  'value' is defined but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/Tests/OneExplorer/ConfigObject.test.ts
  783:15  error  'tracePath' is assigned a value but never used  no-unused-vars
  813:15  error  'tracePath' is assigned a value but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/Tests/OneExplorer/OneExplorer.test.ts
  22:117  error  'DirectoryNode' is defined but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/Tests/OneExplorer/OneStorage.test.ts
  183:15  error  'modelPath' is assigned a value but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/Tests/Toolchain/ToolchainEnv.test.ts
  130:14  error  '_reason' is defined but never used  no-unused-vars
  139:33  error  '_value' is defined but never used   no-unused-vars
  151:12  error  '_value' is defined but never used   no-unused-vars
  154:12  error  '_reason' is defined but never used  no-unused-vars
  163:14  error  '_value' is defined but never used   no-unused-vars
  166:14  error  '_reason' is defined but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/Tests/Utils/PipedSpawn.test.ts
  42:13  error  'cat' is assigned a value but never used  no-unused-vars
  67:47  error  'signal' is defined but never used        no-unused-vars

/home/dayo/git/ONE-vscode/src/Toolchain/DefaultToolchain.ts
  20:9  error  'Logger' is defined but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/Toolchain/ToolchainEnv.ts
  25:9   error  'Balloon' is defined but never used  no-unused-vars
  26:13  error  'helpers' is defined but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/Utils/MultiStepInput.ts
  60:20  error  'T' is defined but never used  no-unused-vars
  65:25  error  'T' is defined but never used  no-unused-vars
  83:29  error  'T' is defined but never used  no-unused-vars

/home/dayo/git/ONE-vscode/src/View/InstallQuickInput.ts
   28:8   error  'resolve' is defined but never used  no-unused-vars
   28:17  error  'reject' is defined but never used   no-unused-vars
  271:53  error  'state' is defined but never used    no-unused-vars

/home/dayo/git/ONE-vscode/src/View/PasswordQuickInput.ts
  21:11  error  Unexpected control character(s) in regular expression: \x00  no-control-regex

✖ 71 problems (71 errors, 0 warnings)


@dayo09
Copy link
Contributor Author

dayo09 commented Sep 6, 2022

Remove no-case-declarations

https://eslint.org/docs/latest/rules/no-case-declarations

Why is this a problem?

The reason is that the lexical declaration is visible in the entire switch block but it only gets initialized when it is assigned, which will only happen if the case where it is defined is reached.

Sol

To ensure that the lexical declaration only applies to the current case clause wrap your clauses in blocks.

2 Errors

/home/dayo/git/ONE-vscode/src/CfgEditor/CfgEditorPanel.ts
  146:11  warning  Unexpected lexical declaration in case block  no-case-declarations
  152:11  warning  Unexpected lexical declaration in case block  no-case-declarations

✖ 2 problems (0 errors, 2 warnings)

@dayo09
Copy link
Contributor Author

dayo09 commented Sep 6, 2022

Remove no-useless-escape

https://eslint.org/docs/latest/rules/no-useless-escape

Escaping non-special characters in strings, template literals, and regular expressions doesn’t have any effect

/home/dayo/git/ONE-vscode/src/CircleGraph/CircleGraphCtrl.ts
  366:26  warning  Unnecessary escape character: \%  no-useless-escape

/home/dayo/git/ONE-vscode/src/PartEditor/PartEditor.ts
  414:26  warning  Unnecessary escape character: \%  no-useless-escape

✖ 2 problems (0 errors, 2 warnings)

@dayo09
Copy link
Contributor Author

dayo09 commented Sep 6, 2022

Remove no-control-regex

Reference

https://stackoverflow.com/questions/14313183/javascript-regex-how-do-i-check-if-the-string-is-ascii-only

Problematic lines

// NOTE ASCII characters have codes ranging from u+0000 to u+007f
function containsNonAscii(str: string): boolean {
  return !/^[\u0000-\u007f]*$/.test(str);
}

The line is required to check if it's an ascii, but how about checking 'printable ascii' aside from those problematic non-printables?

@dayo09
Copy link
Contributor Author

dayo09 commented Sep 6, 2022

Remove no-prototype-builtins

Reference

https://eslint.org/docs/latest/rules/no-prototype-builtins

In ECMAScript 5.1, Object.create was added, which enables the creation of objects with a specified [[Prototype]]. Object.create(null) is a common pattern used to create objects that will be used as a Map. This can lead to errors when it is assumed that objects will have properties from Object.prototype. This rule prevents calling some Object.prototype methods directly from an object.

Additionally, objects can have properties that shadow the builtins on Object.prototype, potentially causing unintended behavior or denial-of-service security vulnerabilities. For example, it would be unsafe for a webserver to parse JSON input from a client and call hasOwnProperty directly on the resulting object, because a malicious client could send a JSON value like {"hasOwnProperty": 1} and cause the server to crash.

To avoid subtle bugs like this, it’s better to always call these methods from Object.prototype. For example, foo.hasOwnProperty("bar") should be replaced with Object.prototype.hasOwnProperty.call(foo, "bar").

Example

Examples of incorrect code for this rule:
var hasBarProperty = foo.hasOwnProperty("bar");
....
Examples of correct code for this rule:
var hasBarProperty = Object.prototype.hasOwnProperty.call(foo, "bar");

@dayo09
Copy link
Contributor Author

dayo09 commented Sep 28, 2022

Remove no-redeclare bleaches

/home/dayo/git/ONE-vscode/src/Job/Job.ts
  45:18  error  'Job' is already defined  no-redeclare

This was referenced Sep 30, 2022
@dayo09
Copy link
Contributor Author

dayo09 commented Oct 25, 2022

Done :-D

@dayo09 dayo09 closed this as completed Oct 25, 2022
This was referenced Oct 25, 2022
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

1 participant