-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(linter): support read env from eslintrc
- Loading branch information
Showing
18 changed files
with
2,295 additions
and
94 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
crates/oxc_cli/fixtures/eslintrc_env/eslintrc_env_browser.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"env": { | ||
"browser": true | ||
}, | ||
"rules": { | ||
"no-undef": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"no-undef": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
//! [Defines environment settings and globals.](https://github.com/eslint/eslintrc/blob/main/conf/environments.js) | ||
|
||
use std::collections::HashMap; | ||
use std::env; | ||
use std::fs::File; | ||
use std::io::{BufWriter, Write}; | ||
use std::path::Path; | ||
|
||
fn main() { | ||
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("environments.rs"); | ||
|
||
let new_globals: HashMap<&str, HashMap<String, bool>> = HashMap::from([ | ||
( | ||
"new_globals_2015", | ||
HashMap::from([ | ||
(String::from("ArrayBuffer"), false), | ||
(String::from("DataView"), false), | ||
(String::from("Float32Array"), false), | ||
(String::from("Float64Array"), false), | ||
(String::from("Int16Array"), false), | ||
(String::from("Int32Array"), false), | ||
(String::from("Int8Array"), false), | ||
(String::from("Map"), false), | ||
(String::from("Promise"), false), | ||
(String::from("Proxy"), false), | ||
(String::from("Reflect"), false), | ||
(String::from("Set"), false), | ||
(String::from("Symbol"), false), | ||
(String::from("Uint16Array"), false), | ||
(String::from("Uint32Array"), false), | ||
(String::from("Uint8Array"), false), | ||
(String::from("Uint8ClampedArray"), false), | ||
(String::from("WeakMap"), false), | ||
(String::from("WeakSet"), false), | ||
]), | ||
), | ||
( | ||
"new_globals_2017", | ||
HashMap::from([ | ||
(String::from("Atomics"), false), | ||
(String::from("SharedArrayBuffer"), false), | ||
]), | ||
), | ||
( | ||
"new_globals_2020", | ||
HashMap::from([ | ||
(String::from("BigInt"), false), | ||
(String::from("BigInt64Array"), false), | ||
(String::from("BigUint64Array"), false), | ||
(String::from("globalThis"), false), | ||
]), | ||
), | ||
( | ||
"new_globals_2021", | ||
HashMap::from([ | ||
(String::from("AggregateError"), false), | ||
(String::from("FinalizationRegistry"), false), | ||
(String::from("WeakRef"), false), | ||
]), | ||
), | ||
]); | ||
|
||
let pre_define_var = HashMap::from([ | ||
(String::from("undefined"), false), | ||
(String::from("Infinity"), false), | ||
(String::from("NaN"), false), | ||
(String::from("eval"), false), | ||
(String::from("arguments"), false), | ||
]); | ||
|
||
// globals.json is copied from [sindresorhus/globals](https://github.com/sindresorhus/globals/blob/870383888c52f48d11d02975f107468f9401024e/globals.json) | ||
// Each global is given a value of true or false. | ||
// A value of true indicates that the variable may be overwritten. | ||
// A value of false indicates that the variable should be considered read-only. | ||
let globals_file = File::open("./globals.json").unwrap(); | ||
let globals: HashMap<String, HashMap<String, bool>> = | ||
serde_json::from_reader(globals_file).unwrap(); | ||
|
||
let mut es2015_2017 = HashMap::new(); | ||
es2015_2017.extend(new_globals["new_globals_2015"].clone()); | ||
es2015_2017.extend(new_globals["new_globals_2017"].clone()); | ||
|
||
let mut es2015_2017_2020 = es2015_2017.clone(); | ||
es2015_2017_2020.extend(new_globals["new_globals_2020"].clone()); | ||
|
||
let mut es2015_2017_2020_2021 = es2015_2017_2020.clone(); | ||
es2015_2017_2020_2021.extend(new_globals["new_globals_2021"].clone()); | ||
|
||
let envs_preset: HashMap<&str, &HashMap<String, bool>> = HashMap::from([ | ||
// Language | ||
("builtin", &globals["builtin"]), | ||
("es6", &new_globals["new_globals_2015"]), | ||
("es2015", &new_globals["new_globals_2015"]), | ||
("es2016", &new_globals["new_globals_2015"]), | ||
("es2017", &es2015_2017), | ||
("es2018", &es2015_2017), | ||
("es2019", &es2015_2017), | ||
("es2020", &es2015_2017_2020), | ||
("es2021", &es2015_2017_2020_2021), | ||
("es2022", &es2015_2017_2020_2021), | ||
("es2023", &es2015_2017_2020_2021), | ||
("es2024", &es2015_2017_2020_2021), | ||
// Platforms | ||
("browser", &globals["browser"]), | ||
("node", &globals["node"]), | ||
("shared-node-browser", &globals["shared-node-browser"]), | ||
("worker", &globals["worker"]), | ||
("serviceworker", &globals["serviceworker"]), | ||
// Frameworks | ||
("commonjs", &globals["commonjs"]), | ||
("amd", &globals["amd"]), | ||
("mocha", &globals["mocha"]), | ||
("jasmine", &globals["jasmine"]), | ||
("jest", &globals["jest"]), | ||
("phantomjs", &globals["phantomjs"]), | ||
("jquery", &globals["jquery"]), | ||
("qunit", &globals["qunit"]), | ||
("prototypejs", &globals["prototypejs"]), | ||
("shelljs", &globals["shelljs"]), | ||
("meteor", &globals["meteor"]), | ||
("mongo", &globals["mongo"]), | ||
("protractor", &globals["protractor"]), | ||
("applescript", &globals["applescript"]), | ||
("nashorn", &globals["nashorn"]), | ||
("atomtest", &globals["atomtest"]), | ||
("embertest", &globals["embertest"]), | ||
("webextensions", &globals["webextensions"]), | ||
("greasemonkey", &globals["greasemonkey"]), | ||
// oxc | ||
("pre_define_var", &pre_define_var), | ||
]); | ||
|
||
let mut envs = phf_codegen::Map::new(); | ||
|
||
for (env_name, preset) in envs_preset { | ||
let mut env = phf_codegen::Map::new(); | ||
for (feature, value) in preset { | ||
env.entry(feature, &value.to_string()); | ||
} | ||
|
||
envs.entry(env_name, &env.build().to_string()); | ||
} | ||
|
||
writeln!( | ||
BufWriter::new(File::create(path).unwrap()), | ||
"#[allow(unused)]\npub static ENVIRONMENTS: phf::Map<&'static str, phf::Map<&'static str, bool>> = {};", | ||
envs.build() | ||
) | ||
.unwrap(); | ||
} |
Oops, something went wrong.