diff --git a/CHANGELOG.md b/CHANGELOG.md index 53f47f66..5edef78b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Added `ignore_pattern` config to `global_usage`, which will ignore any global variables with names that match the pattern - `roblox_incorrect_roact_usage` now checks for incorrect Roact17's `createElement` usage on variables named `React`. For Roact17 only, `key`, `children`, and `ref` are valid properties to Roblox instances. +### Changed +- If `--config` is not defined, `selene.toml` will now be searched for in the current directory and all parent directories. + ### Fixed - `string.pack` and `string.unpack` now have proper function signatures in the Lua 5.3 standard library. - Moved `math.log` second argument addition from Lua 5.3 std lib to 5.2 std lib @@ -404,4 +407,4 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Added standard library chaining. This means you can combine two standard libraries by setting `std` in selene.toml to `std1+std2`. You can chain as many as you want. ## [0.1.0](https://github.com/Kampfkarren/selene/releases/tag/0.1.0) - 2019-11-06 -- Initial release +- Initial release \ No newline at end of file diff --git a/selene/src/main.rs b/selene/src/main.rs index 4042f991..85ec40a2 100644 --- a/selene/src/main.rs +++ b/selene/src/main.rs @@ -494,6 +494,8 @@ fn start(mut options: opts::Options) { None => {} } + let current_dir = std::env::current_dir().unwrap(); + let (config, config_directory): (CheckerConfig, Option) = match options.config { Some(config_file) => { @@ -517,20 +519,29 @@ fn start(mut options: opts::Options) { } } - None => match fs::read_to_string("selene.toml") { - Ok(config_contents) => match toml::from_str(&config_contents) { - Ok(config) => (config, None), - Err(error) => { - error!("Config file not in correct format: {}", error); - std::process::exit(1); - } - }, + None => { + let config_file_path = current_dir + .ancestors() + .map(|path| path.join("selene.toml")) + .find(|path| path.is_file()); - Err(_) => (CheckerConfig::default(), None), - }, - }; + match config_file_path { + Some(config_file) => match fs::read_to_string(&config_file) { + Ok(config_contents) => match toml::from_str(&config_contents) { + Ok(config) => (config, config_file.parent().map(Path::to_path_buf)), + Err(error) => { + error!("Config file not in correct format: {}", error); + std::process::exit(1); + } + }, - let current_dir = std::env::current_dir().unwrap(); + Err(_) => (CheckerConfig::default(), None), + }, + + None => (CheckerConfig::default(), None), + } + } + }; let standard_library = match standard_library::collect_standard_library( &config,