Skip to content

More refactor#222

Closed
lebensterben wants to merge 2 commits intolycheeverse:masterfrom
lebensterben:feature-typed-builder
Closed

More refactor#222
lebensterben wants to merge 2 commits intolycheeverse:masterfrom
lebensterben:feature-typed-builder

Conversation

@lebensterben
Copy link
Member

  • Major changes in lychee-lib::filter module:
    • Fields in Excludes except the RegexSet is now moved to Filter.
    • Filter contains Option<Excludes> and Option<Includes>, which are
      wrapper struct of RegexSet instead of Option<RegexSet>. As a result
      the code now looks cleaner.
    • Factored out some filtering logics to dedicated functions.
      • It's possible to write tests for those functions in addition to tests
        for the Filter struct.
    • Added docs to Filter::is_excluded and reorgnized the code.
  • placed derive_builder by typed_builder:
    • The internal interface very ugly, as admitted by the author, but we no
      longer have nested Options like before.
    • As a result, the Client building is much easier to read.
    • Main benefit of typed_builder is, the arguments feeded to builder is
      checked at compile time instead of run-time.
  • Fixed a bug in lychee::tests::usage and lychee-lib::stats::test.
    • Now it will clear environment variable which would otherwise cause an
      issue if GITHUB_TOKEN is set.
  • Updated dependencies.

@lebensterben
Copy link
Member Author

Let's merge this after #208 and I'll combine rebase it.

@lebensterben lebensterben force-pushed the feature-typed-builder branch from 30b4e33 to f1518f5 Compare April 13, 2021 23:59
use crate::Uri;

// TODO: renaming
// TODO: should just be added to the Excludes set.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great idea! We could call it default_excludes or something

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a second thought, this is doable but will makes the filtering messy.

Because when only includes are provided without excludes, we require URLs to be explicitly included.

If we add false positives as default excludes, this mechanism need to be changed.

So the updated code removed these TODOs.

///
/// 1. If any of the following conditions is met, the URI is excluded:
/// - If it's a mail address and it's configured to ignore mail addresses.
/// - If the IP address belongs to a type that is configured to exclude.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is configured to exclude -> is configured to be excluded

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the grammar is correct.

Consider there's work to be done and there's work to do.
Active infinitive focuses on the agent of action.
This is the documentation of the behaviour of a Filter. So the focus in on Filter.

If you use passive infinitive, the focus transferred to the receiver, which is the Url.


if is_false_positive(input)
// Exclude well-known false-positives
// Performed after checking includes to allow user-overwriddes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overwriddes -> overwrites

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a common misusage.

See the section title: https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html

|| self.is_excludes_match(input)
// If excludes rules matches input, then
// *explicitly excluded*
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the above if conditions, I'd personally also move the comment before the condition. At least I find it easier to read this way, but it's subjective of course. Just wonder if rustfmt would also change the indentation in that case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        if
        // Exclude well-known false-positives
        // Performed after checking includes to allow user-overwriddes
        is_false_positive(input)
                // Previous checks imply input is not explicitly included,
                // if excludes rules is empty, then *presumably excluded*
                || self.is_excludes_empty()
                // If excludes rules matches input, then
                // *explicitly excluded*
            || self.is_excludes_match(input)
        {
            return true;
        }

This is also hard to read

@mre
Copy link
Member

mre commented Apr 14, 2021

I love it. Added some comments. Other than that all good.

@lebensterben lebensterben force-pushed the feature-typed-builder branch 5 times, most recently from 61bc8d5 to 7c4b26b Compare April 15, 2021 02:16
- Major changes in `lychee-lib::filter` module:
  - Fields in `Excludes` except the `RegexSet` is now moved to `Filter`.
  - `Filter` contains `Option<Excludes>` and `Option<Includes>`, which are
    wrapper struct of `RegexSet` instead of `Option<RegexSet>`. As a result
    the code now looks cleaner.
  - Factored out some filtering logics to dedicated functions.
    - It's possible to write tests for those functions in addition to tests
      for the `Filter` struct.
  - Added docs to `Filter::is_excluded` and reorgnized the code.
- placed `derive_builder` by `typed_builder`:
  - The internal interface very ugly, as admitted by the author, but we no
    longer have nested `Option`s like before.
  - As a result, the `Client` building is much easier to read.
  - Main benefit of `typed_builder` is, the arguments feeded to builder is
    checked at compile time instead of run-time.
- Fixed a bug in `lychee::tests::usage` and `lychee-lib::stats::test`.
  - Now it will clear environment variable which would otherwise cause an
    issue if `GITHUB_TOKEN` is set.
- Updated dependencies.
@lebensterben lebensterben force-pushed the feature-typed-builder branch from db439b7 to 631de96 Compare April 15, 2021 02:51
@lebensterben
Copy link
Member Author

The publish error is due to lychee-lib on docs.rs uses derive-builder, so it cannot find the typed-builder dependency.
Again we need to first publish lychee-lib.

Also, this is a breaking change so it would be 0.7.0, or 0.7.0.alpha.

@lebensterben lebensterben mentioned this pull request Apr 15, 2021
@lebensterben
Copy link
Member Author

lebensterben commented Apr 15, 2021

I will make an attempt to improve the builder interface.
I'll try to put the internal builder in a non-public module. And expose a new builder struct with better API interface.
The downside of typed-builder is that it's less flexible. E.g. you cannot provide custom build() function. But I will try to overcome that limitation.

So hold on and don't merge now.

Failed.

@lebensterben lebensterben deleted the feature-typed-builder branch April 15, 2021 16:42
@lebensterben lebensterben mentioned this pull request Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants