Skip to content

Commit

Permalink
feat: find selene.toml in parent directories
Browse files Browse the repository at this point in the history
  • Loading branch information
ProspectPyxis committed Aug 12, 2023
1 parent 9d82de1 commit e5cbfbf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
35 changes: 23 additions & 12 deletions selene/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ fn start(mut options: opts::Options) {
None => {}
}

let current_dir = std::env::current_dir().unwrap();

let (config, config_directory): (CheckerConfig<toml::value::Value>, Option<PathBuf>) =
match options.config {
Some(config_file) => {
Expand All @@ -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,
Expand Down

0 comments on commit e5cbfbf

Please sign in to comment.