Skip to content

Commit 0f4df07

Browse files
better tsconfig error message
1 parent 3ca5647 commit 0f4df07

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

npm-package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "next-css-linter",
3-
"version": "1.4.1",
3+
"version": "1.5.0",
44
"description": "Linter for NextJs CSS modules",
55
"main": "index.js",
66
"scripts": {

src/config.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,8 @@ pub struct Properties {
1414
pub exclude: Vec<String>,
1515
}
1616

17-
pub fn get_compiler_options() -> Properties {
18-
let tsconfig_contents = fs::read_to_string("tsconfig.json")
19-
.expect("Could not load tsconfig. Is the provided directory is typescript project?");
17+
pub fn get_compiler_options() -> anyhow::Result<Properties> {
18+
let tsconfig_contents = fs::read_to_string("tsconfig.json")?;
2019

21-
let v: Properties = match serde_json::from_str(&tsconfig_contents) {
22-
Ok(res) => res,
23-
Err(err) => panic!("{}", err),
24-
};
25-
26-
v
20+
Ok(serde_json::from_str(&tsconfig_contents)?)
2721
}

src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ fn main() -> Result<()> {
6767
);
6868
process::exit(1);
6969
}
70-
let tsconfig = get_compiler_options();
70+
let tsconfig = get_compiler_options().unwrap_or_else(|e| {
71+
eprintln!(
72+
"\n{}Error{}: Could not load tsconfig.json. Is the provided directory is typescript project? ({})",
73+
COLOR_RED, COLOR_RESET, e
74+
);
75+
process::exit(1);
76+
});
7177

7278
let dir = list_files_in_directory(Path::new(".").to_path_buf(), tsconfig.exclude);
7379

0 commit comments

Comments
 (0)