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

ensure that generated validators are up to date #4508

Merged
merged 6 commits into from Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/error-serializer.js
Expand Up @@ -5,6 +5,9 @@



// eslint-disable-next-line
const STR_ESCAPE = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/
Copy link
Member

Choose a reason for hiding this comment

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

If we are going to disable the linter, it would be better to include the rule it is disabling, e.g. // eslint-disable some-rule. However, I have a bigger issue than that:

What does this regular expression do? There needs to at least be a jsdoc block describing the purpose of this regular expression and each component of it. I can't even begin to tell you what this does by just looking at it. It'll be completely impossible to decipher is 2 weeks, much less in 2 years.

Personally, I think that if we are going to start adding so many indecipherable regular expressions to the code then we should start using xregexp to help make them legible.

Copy link
Member

@Eomm Eomm Jan 12, 2023

Choose a reason for hiding this comment

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

This is a generated file, so we rely on ajv here

If the comment has been added manually, it could be the cause for the failing CI - we need to add the generated files to the eslint ignore list

Copy link
Member

Choose a reason for hiding this comment

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

lib/error-serializer.js is a auto-generated file. We should not expect any manual change here.
Any changes should made on https://github.com/fastify/fast-json-stringify


class Serializer {
constructor (options = {}) {
switch (options.rounding) {
Expand Down Expand Up @@ -99,6 +102,11 @@ class Serializer {
str = str.toString()
}

// Fast escape chars check
if (!STR_ESCAPE.test(str)) {
jsumners marked this conversation as resolved.
Show resolved Hide resolved
return quotes + str + quotes
}

if (str.length < 42) {
return this.asStringSmall(str)
} else {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -8,6 +8,7 @@
"scripts": {
"bench": "branchcmp -r 2 -g -s \"npm run benchmark\"",
"benchmark": "npx concurrently -k -s first \"node ./examples/benchmark/simple.js\" \"npx autocannon -c 100 -d 30 -p 10 localhost:3000/\"",
"build:validation": "node build/build-error-serializer.js && node build/build-validation.js",
"coverage": "npm run unit -- --cov --coverage-report=html",
"coverage:ci": "npm run unit -- --cov --coverage-report=html --no-browser --no-check-coverage -R terse",
"coverage:ci-check-coverage": "nyc check-coverage --branches 100 --functions 100 --lines 100 --statements 100",
Expand All @@ -19,8 +20,9 @@
"lint:typescript": "eslint -c types/.eslintrc.json types/**/*.d.ts test/types/**/*.test-d.ts",
"prepublishOnly": "PREPUBLISH=true tap --no-check-coverage test/build/**.test.js",
"test": "npm run lint && npm run unit && npm run test:typescript",
"test:ci": "npm run unit -- -R terse --cov --coverage-report=lcovonly && npm run test:typescript",
"test:ci": "npm run test:validator:integrity && npm run unit -- -R terse --cov --coverage-report=lcovonly && npm run test:typescript",
"test:report": "npm run lint && npm run unit:report && npm run test:typescript",
"test:validator:integrity": "npm run build:validation && git diff --quiet lib/error-serializer.js && git diff --quiet lib/configValidator.js",
Eomm marked this conversation as resolved.
Show resolved Hide resolved
"test:typescript": "tsc test/types/import.ts && tsd",
"test:watch": "npm run unit -- -w --no-coverage-report -R terse",
"unit": "tap",
Expand Down