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

implemneted ejs, php detection #1157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions src/quick-lint-js/diag/diagnostic-types-2.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ QLJS_RESERVED_DIAG("E0279")
QLJS_RESERVED_DIAG("E0391")
QLJS_RESERVED_DIAG("E0707")

struct Diag_EJS_or_PHP_Syntax_Detected {
[[qljs::diag("E0991", Diagnostic_Severity::warning)]] //
[[qljs::message("Detected potential EJS or PHP syntax",
ARG(span))]] //
Source_Code_Span span;
};

struct Diag_Abstract_Field_Cannot_Have_Initializer {
[[qljs::diag("E0295", Diagnostic_Severity::error)]] //
[[qljs::message("abstract fields cannot have default values",
Expand Down
12 changes: 10 additions & 2 deletions src/quick-lint-js/fe/lex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,16 @@ bool Lexer::try_parse_current_token() {
break;

case '<':
if (this->input_[1] == '!' && this->input_[2] == '-' &&
this->input_[3] == '-') {
// checking for EJS or PHP syntax
if((this->input_[0] == '<' && (this->input_[1] == '%')) || (this->input_[0] == '?')){
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Checking this->input_[0] == '<' is redundant. (Line 434 already checks for '<'.)

this->diag_reporter_->report(Diag_EJS_or_PHP_Syntax_Detected{
Source_Code_Span(&this->input_[0], &this->input_[2])
});
// moving the input pointer after detecting sequence
this->input_+=2;
return false;
}else if (this->input_[1] == '!' && this->input_[2] == '-' &&
this->input_[3] == '-') {
this->input_ += 4;
this->skip_line_comment_body();
return false;
Expand Down
5 changes: 5 additions & 0 deletions test/test-parse-warning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class Test_Parse_Warning : public Test_Parse_Expression {};
class Test_Error_Equals_Does_Not_Distribute_Over_Or
: public Test_Parse_Expression {};

TEST_F(Test_Parse_Warning, warn_on_ejs_or_php_syntax) {
test_lex("window.audioRecordingBitRate = <%= audioRecordingBitRate %>;",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Include a test for PHP-style syntax as well.

" ^^^ Diag_EJS_or_PHP_Syntax_Detected"_diag);
}
Comment on lines +34 to +37
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: Put this test in test-lex.cpp, not here.


TEST_F(Test_Parse_Warning, condition_with_assignment_from_literal) {
{
Spy_Visitor p = test_parse_and_visit_statement(
Expand Down