-
Notifications
You must be signed in to change notification settings - Fork 6
Feat(options): add profile option support #211
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
Feat(options): add profile option support #211
Conversation
I'm noticing quite a few extraneous changes throughout the codebase in this PR, which may have been unintentional. Things like formatting differences for tables, changing the style of apostrophes, etc. Do you mind reverting those so the diff can more narrowly focus on the changes that are directly related to supporting the new customizable |
README.md
Outdated
|
||
// Or with options | ||
const resultWithOptions = await cssValidator.validateText('.foo { text-align: center; }', { | ||
profile: 'css3svg', // Validation profile (css3, css3svg, css2, etc.) | ||
medium: 'print', // Media type | ||
warningLevel: 3, // Return warnings | ||
timeout: 5000, // Request timeout in ms | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we do already offer other options, but didn't already have an example showing how to use those in the README, I don't believe adding another option necessitates adding this example here. The README isn't intended to be a replacement for the complete documentation, but rather, just succinctly highlighting the basic usage to showcase how easy it is to use. We'll leave the full spectrum of options documented on the documentation site.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks for the clarification. I've restored the original file as suggested.
src/types/options.ts
Outdated
@@ -1,6 +1,7 @@ | |||
interface OptionsBase { | |||
medium?: 'all' | 'braille' | 'embossed' | 'handheld' | 'print' | 'projection' | 'screen' | 'speech' | 'tty' | 'tv'; | |||
timeout?: number; | |||
profile?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like medium
above, we ought to have a union with all of the valid options. This will catch problems at compile time, rather than runtime, and will allow software engineers to see all of the available options in their IDE and use autocompletion. I believe the available options were documented in #143, though the list might be outdated since it's a couple of years old.
This change would also impact the documentation files, which should list all of the valid options rather than just string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion — I've updated the type to use a union with all valid options and also updated the documentation accordingly.
If we use a union for |
Thanks for pointing that out. I actually tried to clean those up intentionally, but I understand it makes the diff noisier. I'll revert the unrelated changes so the focus stays on the customizable profile option. |
Done — I've updated validate-options.ts to include runtime validation for the profile option. |
src/types/parameters.ts
Outdated
@@ -3,6 +3,7 @@ import { Options } from './options'; | |||
interface ParametersBase { | |||
medium: Options['medium']; | |||
warningLevel: Options['warningLevel']; | |||
profile?: Options['profile']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because Options['profile']
is already optional, I don't think ?:
is necessary here. If that's correct (I haven't tested it), then for internal consistency with the other lines above it, let's remove the ?
:
profile?: Options['profile']; | |
profile: Options['profile']; |
The changes do probably make the formatting better, but at least at our company, we always try to keep our diffs as focused as possible so that the documentation trail for changes is clean. Makes it much easier to understand changes if we have to look back on them years later. Anyway, it looks like |
The To me, the new But we don't yet have any tests that ensure I would just request that these tests be added to the existing |
Regarding tests for options passing in
|
Of those, spying seems like the best approach to me, from a simplicity and maintainability perspective. |
I've fixed the formatting issues - I had to manually transfer data line by line because my editor was automatically editing and formatting MD files. I also made this correction: profile: Options['profile']; |
But I can't solve the problems with the tests. |
I can see that all our main package tests passed successfully in the first stage (12 test suites, 58 tests - all green). The errors you see occur in the second stage during integration tests in the "node" project. This happens when rugged (the CI/CD tool) performs the following steps:
The "browser" project works fine, but the "node" project encounters two types of errors:
These integration test failures are likely related to how the "node" project attempts to use our compiled package, rather than with the code implementation we changed. The important thing is that all the core tests of the package itself (our changes) work correctly. The integration issues are a separate concern that requires further analysis, but they're not directly related to our changes regarding the addition of the profile option. |
If you're seeing "Internal Server Error" and "Too Many Requests" errors, that's likely a service issue on W3C's end. Usually, those types of errors will go away on their own, but it's possible that adding more tests has caused the number of requests the testing makes to exceed a rate limiting threshold on W3C's end. Without taking a deeper dive into what's going on, it might just be easier to scrap the addition of the new "Options passing" tests. Although it'd be nice to have that additional coverage, passing the options is a really simple segment of code that probably doesn't benefit as much from regression testing as much as other, more complicated segments of code do. |
Co-authored-by: Wes Cossick <WesCossick@users.noreply.github.com>
Co-authored-by: Wes Cossick <WesCossick@users.noreply.github.com>
✔️ I have updated the documentation according to your recommendations. ✔️ I've followed your advice and removed the "Options passing" test blocks from both validate-text.test.ts and validate-url.test.ts files. The tests are now passing successfully without any "Internal Server Error" or "Too Many Requests" errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, @Alecto! Thanks for being responsive to the changes I requested. I'll get a release published soon 🚀
Released in v1.4.0! |
Closes #143
This PR adds support for custom validation profiles in the
validateURL
andvalidateText
functions of the W3C CSS Validator library. Users can now specify a validation profile (e.g.,css3svg
,css2
, etc.) to better handle CSS with SVG properties or other profiles, withcss3
as the default if no profile is specified.Changes made:
options.ts
andparameters.ts
to support the newprofile
optionbuild-form-data.ts
to accept aprofile
option in the form data (defaults tocss3
)build-request-url-parameters.ts
to include theprofile
option in the query parameters (defaults tocss3
)profile
option in thevalidateURL
andvalidateText
functionsprofile.test.ts
to verify the functionality of the new optionvalidate-url.md
andvalidate-text.md
filesREADME.md
to document the newprofile
option with an example (e.g.,profile: 'css3svg'
)Why this is needed:
As mentioned in issue #143, the current hardcoded
css3
profile causes false-positive errors when validating CSS with SVG properties (e.g.,fill
,stroke
). This change allows users to specify profiles likecss3svg
, making validation more accurate and eliminating the need for custom error filtering.Next steps:
Thank you for reviewing this PR!