Skip to content

lint error on complex_data_type field for primitive type#39

Merged
nishank-bhatnagar merged 3 commits into
mainfrom
complex-data-type-lint-check
May 19, 2026
Merged

lint error on complex_data_type field for primitive type#39
nishank-bhatnagar merged 3 commits into
mainfrom
complex-data-type-lint-check

Conversation

@nishank-bhatnagar
Copy link
Copy Markdown
Collaborator

What

Refines the complex-data-type lint pass for Agentforce so it correctly handles primitive types, and adds focused test coverage for the new behavior.

Why

complex_data_type_name is only meaningful for object and list[object]. Previously:

  • The rule warned when object / list[object] declarations lacked complex_data_type_name / schema.
  • It said nothing when a primitive type (e.g. number, string, id) was declared with a complex_data_type_name, even though that combination is invalid.
  • anything other than object and list does not need a complex_data_type_name to validate — so specifying one on a primitive should be a hard error.

How

dialect/agentforce/src/lint/passes/complex-data-type.ts

  • Renamed isObjectTypeisComplexType, backed by a named set REQURIED_COMPLEX_DATA_TYPE = { object, list[object] }. Anything outside the set is treated as primitive.
  • Merged checkInputs and checkOutputs into a single checkDecls(decls, actionName, kind) to remove duplication; kind ('input' | 'output') only shapes the diagnostic message and gates the input-only schema: escape hatch.
  • Added a new diagnostic code complex-data-type-on-primitive (Error severity): emitted when a non-whitelisted type carries a complex_data_type_name.
  • Kept the existing object-type-missing-schema (Warning) for whitelisted types missing schema info.
  • Updated the file-level doc comment to describe both diagnostics.

Notable design decisions:

  • list[<primitive>] is intentionally classified as primitive (list[object] is the only list variant that supports complex_data_type_name).
  • schema: remains an alternative to complex_data_type_name for inputs only; outputs still require complex_data_type_name.
  • "ID should be deprecated" was scoped out — that belongs in a separate pass.

dialect/agentforce/src/tests/lint.test.ts

Added a describe('complex data type rule', …) block with a wrap(inputs, outputs) helper that builds a minimal subagent AfScript fixture, plus these scenarios:

# Scenario Expected
1 primitive (number) input + complex_data_type_name Error complex-data-type-on-primitive
2 primitive (number) input, no complex_data_type_name no error
3 primitive (string) output + complex_data_type_name Error
4 it.each over boolean, integer, id, date, datetime, time, timestamp, currency, long with complex_data_type_name Error per case
5 object input + complex_data_type_name no diagnostic
6 object input + schema: no diagnostic
7 list[object] output + complex_data_type_name no diagnostic
8 list[string] input + complex_data_type_name Error (list-of-primitive treated as primitive)
9 mixed: primitive-with-cdtn input + bare object output both Error and Warning fire with correct names

Test Plan

  • Existing tests pass — pnpm vitest run src/tests/lint.test.ts125 passed, including the pre-existing 'warns with actions:' warning case.
  • New tests cover the change — see scenarios 1-9 above.
  • Type checks pass — pnpm typecheck clean (no pnpm lint script in this package).

Checklist

  • My code follows the project's coding style
  • I have reviewed my own diff (git diff main — 2 files, 223 insertions / 43 deletions; logic isolated to complex-data-type.ts and tests)
  • I have added/updated documentation as needed (updated only the file-level JSDoc on the lint pass; no external docs reference this rule)
  • This change does not introduce new warnings

Copy link
Copy Markdown
Member

@setu4993 setu4993 left a comment

Choose a reason for hiding this comment

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

Looks good, nice update.

obj,
lintDiagnostic(
getDeclRange(obj),
`Action ${kind} '${paramName}' in '${actionName}' has primitive type '${typeText}' and must not specify 'complex_data_type_name'. Only 'object' and 'list[object]' types support 'complex_data_type_name'.`,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this correct? i.e. we want to error out? That'll cause some differing behavior for existing agent scripts.

If that is desirable, it works for me, just that we'll need to announce.

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.

No, you are right we don't want to cause any regression for existing agent scripts so modified this to just warning for now and we can introduce hard error in the future.

@nishank-bhatnagar nishank-bhatnagar merged commit f5351a9 into main May 19, 2026
6 checks passed
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.

2 participants