Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to find selene.toml in parent directories #543

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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