Skip to content

Commit

Permalink
Change use_small_heuristics to an enum and stabilise
Browse files Browse the repository at this point in the history
Since it is now an enum, we can be future compatible since we can add variants
for different heuristics.

Closes #1974
  • Loading branch information
nrc committed Jun 19, 2018
1 parent a1c5c46 commit 261238e
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

- `use_small_heuristics` changed to be an enum and stabilised. Configuration
options are now ready for 1.0.

## [0.4.1] 2018-03-16

### Added
Expand Down
10 changes: 5 additions & 5 deletions Configurations.md
Expand Up @@ -275,11 +275,11 @@ fn lorem<Ipsum, Dolor, Sit, Amet>() -> T

Whether to use different formatting for items and expressions if they satisfy a heuristic notion of 'small'.

- **Default value**: `true`
- **Possible values**: `true`, `false`
- **Stable**: No
- **Default value**: `Default`
- **Possible values**: `Default`, `Off`
- **Stable**: Yess

#### `true` (default):
#### `Default` (default):

```rust
enum Lorem {
Expand Down Expand Up @@ -309,7 +309,7 @@ fn main() {
}
```

#### `false`:
#### `Off`:

```rust
enum Lorem {
Expand Down
2 changes: 1 addition & 1 deletion src/config/config_type.rs
Expand Up @@ -399,7 +399,7 @@ macro_rules! create_config {
}

fn set_heuristics(&mut self) {
if self.use_small_heuristics.2 {
if self.use_small_heuristics.2 == Heuristics::Default {
let max_width = self.max_width.2;
self.set().width_heuristics(WidthHeuristics::scaled(max_width));
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/config/mod.rs
Expand Up @@ -41,8 +41,8 @@ create_config! {
hard_tabs: bool, false, true, "Use tab characters for indentation, spaces for alignment";
tab_spaces: usize, 4, true, "Number of spaces per tab";
newline_style: NewlineStyle, NewlineStyle::Unix, true, "Unix or Windows line endings";
use_small_heuristics: bool, true, false, "Whether to use different formatting for items and \
expressions if they satisfy a heuristic notion of 'small'.";
use_small_heuristics: Heuristics, Heuristics::Default, true, "Whether to use different \
formatting for items and expressions if they satisfy a heuristic notion of 'small'.";
indent_style: IndentStyle, IndentStyle::Block, false, "How do we indent expressions or items.";

// Comments and strings
Expand Down Expand Up @@ -236,7 +236,7 @@ mod test {
create_config! {
// Options that are used by the generated functions
max_width: usize, 100, true, "Maximum width of each line";
use_small_heuristics: bool, true, false,
use_small_heuristics: Heuristics, Heuristics::Default, true,
"Whether to use different formatting for items and \
expressions if they satisfy a heuristic notion of 'small'.";
license_template_path: String, String::default(), false,
Expand Down
7 changes: 7 additions & 0 deletions src/config/options.rs
Expand Up @@ -151,6 +151,13 @@ configuration_option_enum! { TypeDensity:
Wide,
}

configuration_option_enum! { Heuristics:
// Turn off any heuristics
Off,
// Use Rustfmt's defaults
Default,
}

impl Density {
pub fn to_list_tactic(self) -> ListTactic {
match self {
Expand Down
2 changes: 1 addition & 1 deletion tests/source/chains.rs
@@ -1,5 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-use_small_heuristics: false
// rustfmt-use_small_heuristics: Off
// Test chain formatting.

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/target/chains.rs
@@ -1,5 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-use_small_heuristics: false
// rustfmt-use_small_heuristics: Off
// Test chain formatting.

fn main() {
Expand Down

0 comments on commit 261238e

Please sign in to comment.