Skip to content

Allow to configure flatc diagnostics (was: disable lowercase snakecase warning for fields) - #9244

Open
hasselmm wants to merge 3 commits into
google:masterfrom
hasselmm:bugfix/9243/allow-to-disable-lowercase-snakecase-warning-for-fields
Open

hasselmm wants to merge 3 commits into
google:masterfrom
hasselmm:bugfix/9243/allow-to-disable-lowercase-snakecase-warning-for-fields

Conversation

@hasselmm

Copy link
Copy Markdown

Problem

flatc has two knobs for diagnostics, and they are binary.
--no-warnings silences all of them, --warnings-as-errors promotes all
of them. There is nothing in between.

That leaves any project that has consciously decided not to follow one
particular recommendation with two bad options. The recurring case is the
field naming warning from #6005: schemas that mirror or are generated from
an existing code base cannot rename their fields without breaking the very
thing they exist to describe. Such a project can either

  • accept the warning, and have it repeat for every field on every build
    until real diagnostics are invisible in the noise, or
  • pass --no-warnings, and give up every other diagnostic flatc offers.

The second is especially painful in CI, where --warnings-as-errors is
exactly what you want for the warnings you have not opted out of — and
it is unreachable today, because opting out of one warning means opting
out of all of them.

This has now come up in #6032, #7111, #8612 and #9243.

What this changes

Both options take an optional, comma separated list of warning keys:

# inhibit one warning, keep the rest
flatc --cpp --no-warnings=strict-field-names schema.fbs

# ... and still fail the build on anything that is left
flatc --cpp --no-warnings=strict-field-names --warnings-as-errors schema.fbs
Key Warning
strict-field-names a field name is not lowercase snake_case
implied-attribute an attribute is already implied by another one
repeated-attribute an attribute is given more than once
unsigned-bit-flags a bit_flags enum has a signed underlying type
all all of the above

A warning inhibited by --no-warnings is never reported and therefore
never becomes an error, which is the behaviour --no-warnings already has
today with respect to --warnings-as-errors.

What this does not change

  • No default behaviour change. Every warning stays on by default.
  • No new command line option. Both spellings already exist.
  • No existing command line is affected. Without an argument both
    options behave exactly as before. Only the = form takes a list, so
    flatc --no-warnings schema.fbs still treats schema.fbs as input.
  • The warnings themselves are untouched — same conditions, same
    wording, same locations.

Notes for review

  • Unknown keys are a hard error rather than being ignored. A silently
    accepted typo would leave the warning enabled and make the option
    useless in CI, which is the main place it is wanted.
  • IDLOptions::no_warnings becomes disabled_warnings and
    warnings_as_errors becomes a WarningFlags bit set. Both members are
    renamed rather than retyped in place, so downstream code assigning a
    bool fails to compile instead of silently meaning "one warning".
  • IDLOptions::Warning follows the Language/lang_to_generate pattern
    already in IDLOptions: an unscoped k-prefixed enum with a fixed
    underlying type, stored in an integer. No casts, no operator overloads.
  • Adding a future warning is one enumerator plus one row in
    warning_options; the parser and the --help text share that table.
  • --warnings-as-errors was not documented in flatc.md at all. It is
    now.

Tested with FLATBUFFERS_STRICT_MODE=ON; flattests passes at each
commit, and the new cases cover per-key inhibition, per-key promotion, key
combination, and the interaction between the two options.

Closes #9243.

This patch allows to disable the lowercase snake_case warning via the
global `--no-warnings` command line option. Simple, but maybe too broad.

The patch also adds tests to test if `--no-warnings` successfully
disables the snake_case warning.

This partly fixes google#9243, but not in a nice way.
`--no-warnings` currently is all or nothing: either every diagnostic the
parser emits is shown, or none of them are. Projects that cannot follow
one particular recommendation therefore have to choose between build
logs spammed by a warning they have consciously decided to accept, and
losing every other warning along with it. Neither is acceptable when a
real problem must not drown in the noise.

Give `--no-warnings` an optional, comma separated list of keys naming the
warnings to inhibit. Without an argument it keeps inhibiting all of them,
so existing command lines are unaffected. Only the `=` form takes an
argument, because `flatc --no-warnings schema.fbs` is valid usage and
must keep treating `schema.fbs` as an input file.

An inhibited warning is not reported and does not set `has_warning_`,
which preserves the established interaction with `--warnings-as-errors`:
what is not warned about cannot fail the build.

Unknown keys are rejected rather than ignored. A silently accepted typo
would leave the warning enabled and make the option useless in CI.

`IDLOptions::no_warnings` becomes `IDLOptions::disabled_warnings`, a bit
set of the new `IDLOptions::Warning` values. The member is renamed rather
than retyped in place so that code still assigning a `bool` to it fails
to compile instead of silently inhibiting a single warning.

This fixes issue google#9243.
`--warnings-as-errors` is all or nothing, which makes it unusable next to
`--no-warnings=<keys>`: a project that has consciously accepted one
recommendation still wants the remaining warnings to fail its builds, and
today it can only choose between failing on all of them or on none.

Give `--warnings-as-errors` the same optional, comma separated list of
keys that `--no-warnings` accepts. Without an argument it keeps promoting
every warning, so existing command lines are unaffected, and as with
`--no-warnings` only the `=` form takes an argument.

`Parser` now records which warnings it has reported rather than just
whether it reported any, so that a warning can be promoted individually.
A warning inhibited by `--no-warnings` is never reported and therefore
never becomes an error, which keeps the established interaction between
the two options intact.

Also document `--warnings-as-errors`, which was missing from flatc.md
entirely.

This is a logical addition to the fix for issue google#9243.
@github-actions github-actions Bot added c++ codegen Involving generating code from schema documentation Documentation labels Sep 14, 2026
@google-cla

google-cla Bot commented Sep 14, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@hasselmm hasselmm changed the title Bugfix/9243/allow to disable lowercase snakecase warning for fields Allow to configure flatc diagnostics (was: disable lowercase snakecase warning for fields) Sep 14, 2026
@hasselmm

Copy link
Copy Markdown
Author

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

CLA should be signed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ codegen Involving generating code from schema documentation Documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to disable lowercase snake_case warning for fields

1 participant