Skip to content

Commit 913b1b3

Browse files
committed
refactor(linter): rename GlobalValue::Writeable to Writable (#16609)
"Writeable" is a mis-spelling. In addition: Oxlint docs say: > You may also use `"writeable"` or `true` to represent `"writable"`. [ESLint's docs](https://eslint.org/docs/v8.x/use/configure/language-options#using-configuration-files-1) state "writable" (without an "e") as the name of the option. This suggests that "writable" is the "real" name of this option, and "writeable" (with an "e") is an alias provided for backwards compat. Therefore, I think it makes more sense to call the enum variant `GlobalValue::Writable` (with the correct spelling). Main motivation is that it means globals get serialized with the right spelling, allowing removing a JS-side workaround from JS plugins code (#16610). For consistency, I've changed "writeable" to "writable" in all test cases, except for 1 test which specifically aims to check that that "legacy" spelling is accepted. https://github.com/oxc-project/oxc/blob/00c5614d1f1bb3465ba7aa5ad668a936b8ec1266/crates/oxc_linter/src/config/globals.rs#L161-L168
1 parent 198e6e2 commit 913b1b3

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

apps/oxlint/fixtures/overrides_env_globals/.oxlintrc.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"jquery": false
1515
},
1616
"globals": {
17-
"Foo": "writeable"
17+
"Foo": "writable"
1818
}
1919
},
2020
{
@@ -25,8 +25,8 @@
2525
"jquery": false
2626
},
2727
"globals": {
28-
"Foo": "writeable"
28+
"Foo": "writable"
2929
}
3030
}
3131
]
32-
}
32+
}

crates/oxc_linter/src/config/config_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ mod test {
673673
files: GlobSet::new(vec!["*.tsx"]),
674674
env: None,
675675
plugins: None,
676-
globals: Some(from_json!({ "React": "readonly", "Secret": "writeable" })),
676+
globals: Some(from_json!({ "React": "readonly", "Secret": "writable" })),
677677
rules: ResolvedOxlintOverrideRules { builtin_rules: vec![], external_rules: vec![] },
678678
}]);
679679

@@ -739,7 +739,7 @@ mod test {
739739
plugins: LintPlugins::ESLINT,
740740
globals: from_json!({
741741
"React": "readonly",
742-
"Secret": "writeable"
742+
"Secret": "writable"
743743
}),
744744
..Default::default()
745745
};

crates/oxc_linter/src/config/globals.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,15 @@ impl OxlintGlobals {
6161
#[serde(rename_all = "lowercase")]
6262
pub enum GlobalValue {
6363
Readonly,
64-
// TODO: #[serde(rename = "writable")] for ESLint compatibility
65-
Writeable,
64+
Writable,
6665
Off,
6766
}
6867

6968
impl GlobalValue {
7069
pub const fn as_str(self) -> &'static str {
7170
match self {
7271
Self::Readonly => "readonly",
73-
Self::Writeable => "writeable",
72+
Self::Writable => "writable",
7473
Self::Off => "off",
7574
}
7675
}
@@ -88,7 +87,7 @@ impl<'de> Deserialize<'de> for GlobalValue {
8887
impl From<bool> for GlobalValue {
8988
#[inline]
9089
fn from(value: bool) -> Self {
91-
if value { GlobalValue::Writeable } else { GlobalValue::Readonly }
90+
if value { GlobalValue::Writable } else { GlobalValue::Readonly }
9291
}
9392
}
9493

@@ -98,7 +97,7 @@ impl TryFrom<&str> for GlobalValue {
9897
fn try_from(value: &str) -> Result<Self, Self::Error> {
9998
match value {
10099
"readonly" | "readable" => Ok(GlobalValue::Readonly),
101-
"writable" | "writeable" => Ok(GlobalValue::Writeable),
100+
"writable" | "writeable" => Ok(GlobalValue::Writable),
102101
"off" => Ok(GlobalValue::Off),
103102
_ => Err("Invalid global value"),
104103
}
@@ -181,7 +180,7 @@ mod test {
181180
#[test]
182181
fn test_override_globals() {
183182
let mut globals = OxlintGlobals::deserialize(&serde_json::json!({
184-
"Foo": "writeable",
183+
"Foo": "writable",
185184
}))
186185
.unwrap();
187186
let override_globals = OxlintGlobals::deserialize(&serde_json::json!({

crates/oxc_linter/src/snapshots/schema_json.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ expression: json
232232
"type": "string",
233233
"enum": [
234234
"readonly",
235-
"writeable",
235+
"writable",
236236
"off"
237237
]
238238
},

editors/vscode/tests/test-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path = require('path');
44

55
type OxlintConfigPlugins = string[];
66
type OxlintConfigCategories = Record<string, unknown>;
7-
type OxlintConfigGlobals = Record<string, 'readonly' | 'writeable' | 'off'>;
7+
type OxlintConfigGlobals = Record<string, 'readonly' | 'writable' | 'off'>;
88
type OxlintConfigEnv = Record<string, boolean>;
99
type OxlintConfigIgnorePatterns = string[];
1010
type OxlintRuleSeverity = 'off' | 'warn' | 'error';

npm/oxlint/configuration_schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
"type": "string",
229229
"enum": [
230230
"readonly",
231-
"writeable",
231+
"writable",
232232
"off"
233233
]
234234
},

0 commit comments

Comments
 (0)