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

quoted-strings: Add extra-required and extra-allowed options #252

Merged
merged 4 commits into from
Apr 17, 2020

Conversation

adrienverge
Copy link
Owner

@adrienverge adrienverge commented Apr 10, 2020

config: Allow rules to validate their configuration


config: Allow generic types inside lists

For example it's possible to define a conf like:

rule:
  foo: [str],
  bar: [int, bool, 'magic'],

quoted-strings: Add options extra-required and extra-allowed

Add ability to:

  • require strings to be quoted if they match a pattern (PCRE regex)
  • allow quoted strings if they match a pattern, while require: only-when-needed is enforced.

Co-Authored-By: Leo Feyer (#246)

@coveralls
Copy link

coveralls commented Apr 10, 2020

Coverage Status

Coverage increased (+0.04%) to 97.935% when pulling 244b30d on feat/quoted-strings-extras into 483a8d8 on master.

@adrienverge
Copy link
Owner Author

@leofeyer @ruipinge feel free to comment on the implementation. Are there any use-cases uncovered?

To summarize:

  • With quoted-strings: {required: false, extra-required: [^http://, ^ftp://]}

    • the following code snippet would PASS:

      - localhost
      - "localhost"
      - "http://localhost"
      - "ftp://localhost"
    • the following code snippet would FAIL:

      - http://localhost
      - ftp://localhost
  • With quoted-strings: {required: only-when-needed, extra-allowed: [^http://, ^ftp://], extra-required: [QUOTED]}

    • the following code snippet would PASS:

      - localhost
      - "http://localhost"
      - "ftp://localhost"
      - "this is a string that needs to be QUOTED"
    • the following code snippet would FAIL:

      - "localhost"
      - this is a string that needs to be QUOTED

@adrienverge adrienverge force-pushed the feat/quoted-strings-extras branch 3 times, most recently from 37cf8f4 to 9721fd1 Compare April 13, 2020 12:28
For example it's possible to define a conf like:

    rule:
      foo: [str],
      bar: [int, bool, 'magic'],
Add ability to:
- require strings to be quoted if they match a pattern (PCRE regex)
- allow quoted strings if they match a pattern, while `require:
  only-when-needed` is enforced.

Co-Authored-By: Leo Feyer (#246)
@adrienverge adrienverge merged commit b711fd9 into master Apr 17, 2020
@adrienverge adrienverge deleted the feat/quoted-strings-extras branch April 17, 2020 08:30
@leofeyer
Copy link

🎉

Thank you @adrienverge.

@adrienverge
Copy link
Owner Author

You're welcome, and thanks for your help on this.

For info, if your use case is just strings starting with %, it should be fixed by #254. You don't have to change your configuration.

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.

None yet

3 participants