mozilla / eslint-plugin-no-unsanitized

Custom ESLint rule to disallows unsafe innerHTML, outerHTML, insertAdjacentHTML and alike
Mozilla Public License 2.0
231 stars 38 forks source link

Cannot run eslint in a subdirectory of a project #255

Closed jfx2006 closed 1 month ago

jfx2006 commented 1 month ago

Short version: If you run eslint from a subdirectory of a project, when the no-unsanitized plugin loads, it fails because of the readFileSync("./package.json") line in index.js.

This caused a problem for Thunderbird which always runs mach eslint in the comm/ subdirectory so it uses the right eslint configuration.

STR:

Fails with: Error: Failed to load plugin 'no-unsanitized' declared in '../.eslintrc.js » plugin:mozilla/recommended': ENOENT: no such file or directory, open './package.json'

I was able to minimally reproduce with a small js project with eslint and no-unsantized as well.

I suspect the intent was to read the package.json from this package to fill in the plugin metadata version?

Bug 1921150 filed with workaround fix for Thunderbird. Workaround is to create an empty package.json prior to running eslint and then remove it.