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

New diagnostic type, documentation, and test for if("x" || "y"), case "x" || "y": #993

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

ybl3
Copy link

@ybl3 ybl3 commented Apr 21, 2023

feat: added diagnostic type, documentation, and test case for issue #953
production code not completed yet

@github-actions
Copy link

github-actions bot commented Apr 21, 2023

CLA Assistant Lite bot Thank you for your contribution! Like many free software projects, you must sign our Contributor License Agreement before we can accept your contribution.

EDIT: All contributors have signed quick-lint-js' Contributor License Agreement (CLA-v1.md).

@ybl3
Copy link
Author

ybl3 commented Apr 21, 2023

I have read and hereby agree to quick-lint-js' Contributor License Agreement (CLA-v1.md).

Comment on lines +19 to +21
```typescript
case "x" || "y":
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

Must fix: Examples with bad code belong in the first code block. Also, they must be syntactically valid aside from the diagnostic, so you must include a switch statement.


A condition with a string literal will always evaluate to true

```typescript
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: I prefer examples in documentation to be javascript if possible.

@@ -2976,13 +2986,6 @@
diag_unexpected_colon_after_generic_definition, "E0331", \
diagnostic_severity::error, { source_code_span colon; }, \
MESSAGE(QLJS_TRANSLATABLE("':' should be 'extends' instead"), colon)) \
\
QLJS_DIAG_TYPE( \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Must fix: I think you reverted someone else's commit by mistake (edec089?). Reintroduce this diagnostic.

Comment on lines +343 to +345
for (span_size i = 0; i < ast->child_count() + 1; i++) {
expression* lhs = ast->child(i)->without_paren();
expression* rhs = ast->child(i + 1)->without_paren();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Must fix: Iterating to ast->child_count() + 1 looks wrong. It would mean we potentially access ast->child(ast->child_count()) (lhs) and ast->child(ast->child_count() + 1) (rhs), which are out of bounds.

I think you meant ast->child_count() - 1 instead.


if ((lhs->kind() == expression_kind::literal &&
rhs->kind() == expression_kind::literal) ){
source_code_span op_span = ast->operator_spans_[i];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Must fix: This code does not compile:

no member named 'operator_spans_' in 'quick_lint_js::expression::conditional'

@strager strager linked an issue Apr 21, 2023 that may be closed by this pull request
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.

10$: Warn on if("x"||"y"), case "x"||"y":, etc.
2 participants