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

Use ESLint to lint JavaScript code blocks inside .cshtml (OSOE-585) #9

Open
0liver opened this issue Jul 28, 2022 · 7 comments
Open
Labels
enhancement New feature or request

Comments

@0liver
Copy link
Contributor

0liver commented Jul 28, 2022

Linting external JavaScript files is great, but let's also cover inline script as it's still widely used.

The html plugin already supports inline <script> block in html files - maybe it's enough to add .cshtml to the list of html extensions? Maybe not.

Let's try it out!

Jira issue

@sarahelsaig
Copy link
Member

I think you will get syntax errors from the Razor. Copy a script block into a JS file first to check what can you expect before investing time setting up the plugin,

@0liver
Copy link
Contributor Author

0liver commented Jul 28, 2022

What do you mean by this:

Copy a script block into a JS file first to check what can you expect

?

@sarahelsaig
Copy link
Member

What I wrote in the previous sentence. :) I expect that you will get syntax errors in the script block if you treat cshtml as html. You can verify it by just taking the content of the script block and putting it into a JS file and running ESLint on it.

Also see razor-vue-lint. It doesn't seem to be maintained, but the readme shows an attempt at wrapping Razor syntax for ESLint.

@0liver
Copy link
Contributor Author

0liver commented Jul 28, 2022

Oh, I totally forgot about code inside of script blocks, too - that'd be tricky to work around.

@Piedone
Copy link
Member

Piedone commented Aug 14, 2022

Due to C# and JS being mixed, this would indeed be tricky. I think we can't realistically tackle this, rather, we should focus on having as little inline JS as possible. Serious issues also impacting runtime will then be surfaced during UI tests.

@sarahelsaig
Copy link
Member

Perhaps the html eslint plugin could be invoked by the UI test like we do with html-validate?

@Piedone
Copy link
Member

Piedone commented Aug 14, 2022

Hmm, interesting, yeah, we could do that, I guess.

@Piedone Piedone added the enhancement New feature or request label Mar 6, 2023
@Piedone Piedone changed the title Use ESLint to lint JavaScript code blocks inside .cshtml Use ESLint to lint JavaScript code blocks inside .cshtml (OSOE-585) Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants