Skip to content

Commit

Permalink
Run ESLint on scripts (#984)
Browse files Browse the repository at this point in the history
- Add a package.json
- Change replacements to be valid JS which makes lint run fine
- Add automation test (hopefully)
  • Loading branch information
jonathanKingston authored Nov 3, 2021
1 parent 59ece79 commit 27c7a17
Show file tree
Hide file tree
Showing 20 changed files with 4,379 additions and 750 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
submodules/
25 changes: 25 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"env": {
"browser": true,
"es2017": true
},
"extends": [
"standard"
],
"globals": {
"__firefox__": "readonly",
"SECURITY_TOKEN": "readonly",
"$FEATURE_SETTINGS$": "readonly",
"$GPC_ENABLED$": "readonly",
"$BLOCKING_ENABLED$": "readonly",
"$TRACKER_DATA$": "readonly",
"$IS_DEBUG$": "readonly",
"webkit": "readonly"
},
"parserOptions": {
"ecmaVersion": 7
},
"rules": {
"indent": ["error", 4]
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
build/
DerivedData/
Carthage/Checkouts
node_modules/

## Various settings
*.pbxuser
Expand Down
4 changes: 2 additions & 2 deletions Core/ContentBlockerRulesUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public class ContentBlockerRulesUserScript: NSObject, UserScript {
+ (privacyConfiguration.exceptionsList(forFeature: .contentBlocking).joined(separator: "\n"))

return Self.loadJS("contentblockerrules", from: Bundle.core, withReplacements: [
"${tempUnprotectedDomains}": remoteUnprotectedDomains,
"${userUnprotectedDomains}": privacyConfiguration.userUnprotectedDomains.joined(separator: "\n")
"$TEMP_UNPROTECTED_DOMAINS$": remoteUnprotectedDomains,
"$USER_UNPROTECTED_DOMAINS$": privacyConfiguration.userUnprotectedDomains.joined(separator: "\n")
])
}

Expand Down
2 changes: 1 addition & 1 deletion Core/DoNotSellUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import BrowserServicesKit
public class DoNotSellUserScript: NSObject, UserScript {
public var source: String {
return Self.loadJS("donotsell", from: Bundle.core, withReplacements: [
"${gpcEnabled}": PrivacyConfigurationManager.shared.privacyConfig
"$GPC_ENABLED$": PrivacyConfigurationManager.shared.privacyConfig
.isEnabled(featureKey: .gpc) ? "true" : "false"
])
}
Expand Down
8 changes: 4 additions & 4 deletions Core/FingerprintUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public class FingerprintUserScript: NSObject, UserScript {
.exceptionsList(forFeature: .fingerprintingScreenSize).joined(separator: "\n")

return Self.loadJS("fingerprint", from: Bundle.core, withReplacements: [
"${featureSettings}": featureSettings,
"${tempStorageExceptions}": tempStorageExceptions,
"${batteryExceptions}": batteryExceptions,
"${screenSizeExceptions}": screenSizeExceptions
"$FEATURE_SETTINGS$": featureSettings,
"$TEMP_STORAGE_EXCEPTIONS$": tempStorageExceptions,
"$BATTERY_EXCEPTIONS$": batteryExceptions,
"$SCREEN_SIZE_EXCEPTIONS$": screenSizeExceptions
])
}

Expand Down
2 changes: 1 addition & 1 deletion Core/LoginFormDetectionUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class LoginFormDetectionUserScript: NSObject, UserScript {

public lazy var source: String = {
return Self.loadJS("login-form-detection", from: Bundle.core, withReplacements: [
"${isDebug}": isDebugBuild ? "true" : "false"
"$IS_DEBUG$": isDebugBuild ? "true" : "false"
])
}()

Expand Down
12 changes: 6 additions & 6 deletions Core/SurrogatesUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ public class SurrogatesUserScript: NSObject, UserScript {
}

return Self.loadJS("contentblocker", from: Bundle.core, withReplacements: [
"${isDebug}": isDebugBuild ? "true" : "false",
"${tempUnprotectedDomains}": remoteUnprotectedDomains,
"${userUnprotectedDomains}": privacyConfiguration.userUnprotectedDomains.joined(separator: "\n"),
"${trackerData}": trackerData,
"${surrogates}": configurationSource.surrogates,
"${blockingEnabled}": privacyConfiguration.isEnabled(featureKey: .contentBlocking) ? "true" : "false"
"$IS_DEBUG$": isDebugBuild ? "true" : "false",
"$TEMP_UNPROTECTED_DOMAINS$": remoteUnprotectedDomains,
"$USER_UNPROTECTED_DOMAINS$": privacyConfiguration.userUnprotectedDomains.joined(separator: "\n"),
"$TRACKER_DATA$": trackerData,
"$SURROGATES$": configurationSource.surrogates,
"$BLOCKING_ENABLED$": privacyConfiguration.isEnabled(featureKey: .contentBlocking) ? "true" : "false"
])
}

Expand Down
Loading

0 comments on commit 27c7a17

Please sign in to comment.