JS: Make implicit this receivers explicit

This commit is contained in:
Kasper Svendsen
2023-05-11 10:28:03 +02:00
parent 082e6a1245
commit 489a73c2c3
2 changed files with 19 additions and 15 deletions

View File

@@ -10,10 +10,12 @@ module ESLint {
*/
abstract class Configuration extends Locatable {
/** Gets the folder in which this configuration file is located. */
private Folder getEnclosingFolder() { result = getFile().getParentContainer() }
private Folder getEnclosingFolder() { result = this.getFile().getParentContainer() }
/** Holds if this configuration file applies to the code in `tl`. */
predicate appliesTo(TopLevel tl) { tl.getFile().getParentContainer+() = getEnclosingFolder() }
predicate appliesTo(TopLevel tl) {
tl.getFile().getParentContainer+() = this.getEnclosingFolder()
}
/** Gets the `globals` configuration object of this file, if any. */
abstract ConfigurationObject getGlobals();
@@ -39,11 +41,11 @@ module ESLint {
/** An `.eslintrc.json` file. */
private class EslintrcJson extends JsonConfiguration {
EslintrcJson() {
isTopLevel() and
exists(string n | n = getFile().getBaseName() | n = ".eslintrc.json" or n = ".eslintrc")
this.isTopLevel() and
exists(string n | n = this.getFile().getBaseName() | n = ".eslintrc.json" or n = ".eslintrc")
}
override ConfigurationObject getGlobals() { result = getPropValue("globals") }
override ConfigurationObject getGlobals() { result = this.getPropValue("globals") }
}
/** An ESLint configuration object in JSON format. */
@@ -51,7 +53,7 @@ module ESLint {
override Configuration getConfiguration() { this = result.(JsonConfiguration).getPropValue(_) }
override boolean getBooleanProperty(string p) {
exists(string v | v = getPropValue(p).(JsonBoolean).getValue() |
exists(string v | v = this.getPropValue(p).(JsonBoolean).getValue() |
v = "true" and result = true
or
v = "false" and result = false
@@ -62,7 +64,7 @@ module ESLint {
/** An `.eslintrc.yaml` file. */
private class EslintrcYaml extends Configuration instanceof YamlMapping, YamlDocument {
EslintrcYaml() {
exists(string n | n = getFile().getBaseName() |
exists(string n | n = this.(Locatable).getFile().getBaseName() |
n = ".eslintrc.yaml" or n = ".eslintrc.yml" or n = ".eslintrc"
)
}
@@ -91,7 +93,7 @@ module ESLint {
exists(PackageJson pkg | this = pkg.getPropValue("eslintConfig"))
}
override ConfigurationObject getGlobals() { result = getPropValue("globals") }
override ConfigurationObject getGlobals() { result = this.getPropValue("globals") }
}
/** An ESLint `globals` configuration object. */
@@ -99,10 +101,12 @@ module ESLint {
GlobalsConfigurationObject() { this = any(Configuration cfg).getGlobals() }
override predicate declaresGlobal(string name, boolean writable) {
getBooleanProperty(name) = writable
this.getBooleanProperty(name) = writable
}
override predicate appliesTo(ExprOrStmt s) { getConfiguration().appliesTo(s.getTopLevel()) }
override predicate appliesTo(ExprOrStmt s) {
this.getConfiguration().appliesTo(s.getTopLevel())
}
abstract override Configuration getConfiguration();