Skip to content

[json_syntax_generator] Support String regex patterns - #2441

Merged
dcharkes merged 2 commits into
mainfrom
json-syntax-regex
Jul 24, 2025
Merged

dcharkes merged 2 commits into
mainfrom
json-syntax-regex

Conversation

@dcharkes

@dcharkes dcharkes commented Jul 23, 2025 •

Copy link
Copy Markdown
Collaborator

For dart-lang/sdk#60889, I'd like to avoid copy pasting the following code from pub to dartdev

https://github.com/dart-lang/pub/blob/c3e50919d11896f014cb971e1776d00a0e2d18b3/lib/src/pubspec_parse.dart#L228-L240

So Instead, I want to make a schema for the pubspec.yaml with json_syntax_generator.

Since users might only use dart install to interact with the executables section in the pubspec, we need to make sure our validation is identical to what pub does. This means we need support for regex patterns on strings.

This PR adds support for regex patterns on strings.

The logic is tested by applying it to the pubspec lock which has some places which have regex patterns (package names, hashes, semantic versions.)

Note we have the pubspec lock schema now twice in the repo. The pub formats package already serves as a test, so deleting the test from the syntax generator package.

@github-actions

github-actions Bot commented Jul 23, 2025 •

Copy link
Copy Markdown

PR Health

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbols
License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/jni/lib/src/third_party/generated_bindings.dart
pkgs/native_doc_dartifier/lib/native_doc_dartifier.dart
pkgs/native_doc_dartifier/lib/src/native_doc_dartifier_base.dart
pkgs/objective_c/lib/src/ns_input_stream.dart

@dcharkes
dcharkes force-pushed the json-syntax-regex branch from 7727052 to 539e614 Compare July 23, 2025 14:34
@dcharkes
dcharkes requested a review from goderbauer July 23, 2025 14:34
@dcharkes
dcharkes marked this pull request as ready for review July 23, 2025 14:35
@coveralls

coveralls commented Jul 23, 2025 •

Copy link
Copy Markdown

Coverage Status

coverage: 86.85% (+2.2%) from 84.62%
when pulling 4bf15f5 on json-syntax-regex
into 3ff7b44 on main.

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

"properties": {
"name": {
"type": "string",
"pattern": "^[a-zA-Z_]\\w*$",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

uber-nit: for consistency with the rest move this after the description key?

@dcharkes dcharkes Jul 24, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ah, let me add the jsons in this package to pkgs/hooks/tool/normalize.dart then they will also be consistent everywhere! (We should probably move that normalizer to the toplevel tools/ directory instead of inside a package.)

"properties": {
"name": {
"type": "string",
"pattern": "^[a-zA-Z_]\\w*$",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am in favor of deleting this since pkg:pub_formats seems to be validating the same thing?

@dcharkes
dcharkes merged commit ee47c28 into main Jul 24, 2025
@dcharkes
dcharkes deleted the json-syntax-regex branch July 24, 2025 10:33
auto-submit Bot pushed a commit that referenced this pull request Jul 24, 2025
Follow up of #2441.

This time adding support for regexes on the strings that are the keys of maps.

In order to avoid duplicating:

https://github.com/dart-lang/pub/blob/c3e50919d11896f014cb971e1776d00a0e2d18b3/lib/src/pubspec_parse.dart#L219-L226

Again, tested on the pubspec lock schema.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants