Closed Bug 1774287 Opened 3 years ago Closed 3 years ago

Update `getIsGlobalScope` to cover class static block

Categories

(Developer Infrastructure :: Lint and Formatting, task)

Tracking

(firefox103 fixed)

RESOLVED FIXED
103 Branch
Tracking Status
firefox103 --- fixed

People

(Reporter: arai, Assigned: arai)

References

Details

Attachments

(3 files, 1 obsolete file)

getIsGlobalScope in helpers.js covers functions, but not new things such as class static block, and maybe also class property, depending on what the "is global scope" expects

https://searchfox.org/mozilla-central/rev/170f06a720ddabee44c728b05ad30b18b066acca/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js#494-502,513-520

getIsFunctionNode(node) {
  switch (node.type) {
    case "ArrowFunctionExpression":
    case "FunctionDeclaration":
    case "FunctionExpression":
      return true;
  }
  return false;
},
...
getIsGlobalScope(ancestors) {
  for (let parent of ancestors) {
    if (this.getIsFunctionNode(parent)) {
      return false;
    }
  }
  return true;
},

Apparently we mis-calculate the global variables in the following case:

class C {
  static {
    this.foo = 10;
  }
}

foo becomes a part of global variables because it's not enclosed by function, but this there is class C.

I'll fix the case and add testcase for globals.js

The helper function must be explicit about what it's actually calculating, and each consumer should be explicit about what it wants.

For the case in globals.js, it's about what the this value is. that's not about scope actually, and arrow function should be ignored.

For the case in reject-top-level-await.js, it's about whether it's top-level script or not.

For the case in var-only-at-top-level.js, it's about where the var declaration belongs to, so it's really about scope.

All of them are different conditions.

Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED
Attachment #9282356 - Attachment is obsolete: true
Attachment #9281782 - Attachment description: Bug 1774287 - Part 2: Add helpers.getIsTopLevelScript and helpers.getIsGlobalVar. r?Standard8! → Bug 1774287 - Part 2: Add helpers.getIsTopLevelScript. r?Standard8!
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/608869fc839e Part 1: Add helpers.getIsGlobalThis and use it when handling global variable. r=Standard8 https://hg.mozilla.org/integration/autoland/rev/8d85ca22341e Part 2: Add helpers.getIsTopLevelScript. r=Standard8

Backed out for causing node test failures on globals.js

Failure line: TEST-UNEXPECTED-FAIL | globals.js | should reflect top-level this property assignment | Cannot find module '@babel/plugin-syntax-jsx'

Push with failures

Failure log

Backout link

[task 2022-06-22T12:24:53.943Z] TEST-PASS | consistent-if-bracing.js | if (true) {1} else if (true) {2} else 0
[task 2022-06-22T12:24:53.945Z] TEST-PASS | consistent-if-bracing.js | if (true) {1} else if (true) {2} else if (true) 3; else {0}
[task 2022-06-22T12:24:53.946Z] TEST-PASS | consistent-if-bracing.js | if (true) {if (true) 1; else {0}} else {0}
[task 2022-06-22T12:24:53.954Z] TEST-UNEXPECTED-FAIL | globals.js | should reflect top-level this property assignment | Cannot find module '@babel/plugin-syntax-jsx'
[task 2022-06-22T12:24:53.954Z] Require stack:
[task 2022-06-22T12:24:53.954Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/config/files/plugins.js
[task 2022-06-22T12:24:53.954Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/config/files/index.js
[task 2022-06-22T12:24:53.954Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/index.js
[task 2022-06-22T12:24:53.954Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/worker/babel-core.cjs
[task 2022-06-22T12:24:53.954Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/worker/handle-message.cjs
[task 2022-06-22T12:24:53.954Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/client.cjs
[task 2022-06-22T12:24:53.954Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/index.cjs
[task 2022-06-22T12:24:53.954Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
[task 2022-06-22T12:24:53.954Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/avoid-removeChild.js
[task 2022-06-22T12:24:53.954Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/tests/avoid-removeChild.js
[task 2022-06-22T12:24:53.955Z] TEST-UNEXPECTED-FAIL | globals.js | should reflect this property assignment inside block | Cannot find module '@babel/plugin-syntax-jsx'
[task 2022-06-22T12:24:53.955Z] Require stack:
[task 2022-06-22T12:24:53.955Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/config/files/plugins.js
[task 2022-06-22T12:24:53.955Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/config/files/index.js
[task 2022-06-22T12:24:53.955Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/index.js
[task 2022-06-22T12:24:53.955Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/worker/babel-core.cjs
[task 2022-06-22T12:24:53.955Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/worker/handle-message.cjs
[task 2022-06-22T12:24:53.955Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/client.cjs
[task 2022-06-22T12:24:53.955Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/index.cjs
[task 2022-06-22T12:24:53.956Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
[task 2022-06-22T12:24:53.956Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/avoid-removeChild.js
[task 2022-06-22T12:24:53.956Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/tests/avoid-removeChild.js
[task 2022-06-22T12:24:53.956Z] TEST-UNEXPECTED-FAIL | globals.js | should ignore this property assignment inside function declaration | Cannot find module '@babel/plugin-syntax-jsx'
[task 2022-06-22T12:24:53.956Z] Require stack:
[task 2022-06-22T12:24:53.956Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/config/files/plugins.js
[task 2022-06-22T12:24:53.956Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/config/files/index.js
[task 2022-06-22T12:24:53.956Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/index.js
[task 2022-06-22T12:24:53.956Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/worker/babel-core.cjs
[task 2022-06-22T12:24:53.956Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/worker/handle-message.cjs
[task 2022-06-22T12:24:53.956Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/client.cjs
[task 2022-06-22T12:24:53.956Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/index.cjs
[task 2022-06-22T12:24:53.956Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
[task 2022-06-22T12:24:53.956Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/avoid-removeChild.js
[task 2022-06-22T12:24:53.956Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/tests/avoid-removeChild.js
[task 2022-06-22T12:24:53.957Z] TEST-UNEXPECTED-FAIL | globals.js | should ignore this property assignment inside function expression | Cannot find module '@babel/plugin-syntax-jsx'
[task 2022-06-22T12:24:53.957Z] Require stack:
[task 2022-06-22T12:24:53.957Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/config/files/plugins.js
[task 2022-06-22T12:24:53.957Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/config/files/index.js
[task 2022-06-22T12:24:53.957Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/index.js
[task 2022-06-22T12:24:53.957Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/worker/babel-core.cjs
[task 2022-06-22T12:24:53.957Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/worker/handle-message.cjs
[task 2022-06-22T12:24:53.957Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/client.cjs
[task 2022-06-22T12:24:53.957Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/index.cjs
[task 2022-06-22T12:24:53.957Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
[task 2022-06-22T12:24:53.957Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/avoid-removeChild.js
[task 2022-06-22T12:24:53.957Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/tests/avoid-removeChild.js
[task 2022-06-22T12:24:53.958Z] TEST-UNEXPECTED-FAIL | globals.js | should ignore this property assignment inside method | Cannot find module '@babel/plugin-syntax-jsx'
[task 2022-06-22T12:24:53.958Z] Require stack:
[task 2022-06-22T12:24:53.958Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/config/files/plugins.js
[task 2022-06-22T12:24:53.958Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/config/files/index.js
[task 2022-06-22T12:24:53.958Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/index.js
[task 2022-06-22T12:24:53.958Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/worker/babel-core.cjs
[task 2022-06-22T12:24:53.958Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/worker/handle-message.cjs
[task 2022-06-22T12:24:53.958Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/client.cjs
[task 2022-06-22T12:24:53.958Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/index.cjs
[task 2022-06-22T12:24:53.958Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
[task 2022-06-22T12:24:53.958Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/avoid-removeChild.js
[task 2022-06-22T12:24:53.958Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/tests/avoid-removeChild.js
[task 2022-06-22T12:24:53.959Z] TEST-UNEXPECTED-FAIL | globals.js | should ignore this property assignment inside accessor | Cannot find module '@babel/plugin-syntax-jsx'
[task 2022-06-22T12:24:53.959Z] Require stack:
<...>
[task 2022-06-22T12:24:53.965Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
[task 2022-06-22T12:24:53.965Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/avoid-removeChild.js
[task 2022-06-22T12:24:53.965Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/tests/avoid-removeChild.js
[task 2022-06-22T12:24:53.966Z] TEST-UNEXPECTED-FAIL | globals.js | should ignore this property assignment inside class static private property | Cannot find module '@babel/plugin-syntax-jsx'
[task 2022-06-22T12:24:53.966Z] Require stack:
[task 2022-06-22T12:24:53.966Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/config/files/plugins.js
[task 2022-06-22T12:24:53.966Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/config/files/index.js
[task 2022-06-22T12:24:53.966Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/core/lib/index.js
[task 2022-06-22T12:24:53.966Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/worker/babel-core.cjs
[task 2022-06-22T12:24:53.966Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/worker/handle-message.cjs
[task 2022-06-22T12:24:53.966Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/client.cjs
[task 2022-06-22T12:24:53.966Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/node_modules/@babel/eslint-parser/lib/index.cjs
[task 2022-06-22T12:24:53.966Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
[task 2022-06-22T12:24:53.966Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/avoid-removeChild.js
[task 2022-06-22T12:24:53.966Z] - /builds/worker/checkouts/gecko/tools/lint/eslint/eslint-plugin-mozilla/tests/avoid-removeChild.js
[task 2022-06-22T12:24:53.967Z] TEST-PASS | lazy-getter-object-name.js | |    ChromeUtils.defineESModuleGetters(lazy, {|      Services: "resource://gre/modules/Services.sys.mjs",|    });|
[task 2022-06-22T12:24:53.968Z] TEST-PASS | lazy-getter-object-name.js | |    ChromeUtils.defineESModuleGetters(obj, {|      Services: "resource://gre/modules/Services.sys.mjs",|    });|
[task 2022-06-22T12:24:53.969Z] TEST-PASS | lazy-getter-object-name.js | |    ChromeUtils.defineESModuleGetters(this, {|      Services: "resource://gre/modules/Services.sys.mjs",|    });|
[task 2022-06-22T12:24:53.970Z] TEST-PASS | lazy-getter-object-name.js | |    ChromeUtils.defineESModuleGetters(window, {|      Services: "resource://gre/modules/Services.sys.mjs",|    });|
[task 2022-06-22T12:24:53.972Z] TEST-PASS | mark-exported-symbols-as-used.js | var EXPORTED_SYMBOLS = ['foo'];
Flags: needinfo?(arai.unmht)
Flags: needinfo?(arai.unmht)
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/cc9b5695283b Part 0: Add extra option to helpers.parseCode to ignore babel config. r=Standard8 https://hg.mozilla.org/integration/autoland/rev/3aa5e8a9fa07 Part 1: Add helpers.getIsGlobalThis and use it when handling global variable. r=Standard8 https://hg.mozilla.org/integration/autoland/rev/33eec495fb13 Part 2: Add helpers.getIsTopLevelScript. r=Standard8
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: