-
Notifications
You must be signed in to change notification settings - Fork 6
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
False-negative on JSON import #1
Comments
Here's how I modified the rule to only apply to diff --git a/node_modules/eslint-plugin-require-extensions/index.js b/node_modules/eslint-plugin-require-extensions/index.js
index d531a5e..bf1a83c 100644
--- a/node_modules/eslint-plugin-require-extensions/index.js
+++ b/node_modules/eslint-plugin-require-extensions/index.js
@@ -1,3 +1,14 @@
+const { existsSync } = require('fs')
+const { dirname, resolve } = require('path')
+
+const extensions = ['js', 'ts', 'jsx', 'tsx']
+
+function moduleExists(path) {
+ return ext => {
+ return existsSync(`${path}.${ext}`)
+ }
+}
+
module.exports = {
configs: {
recommended: {
@@ -19,7 +30,9 @@ module.exports = {
const value = source.value;
if (!value) return;
- if (value.startsWith('.') && !value.endsWith('.js')) {
+ if (!value.startsWith('.') || value.endsWith('.js')) return;
+
+ if (extensions.some(moduleExists(resolve(dirname(context.getFilename()), value)))) {
context.report({
node,
message: 'Relative imports and exports must end with .js', |
is this planned on getting accepted? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This could potentially affect other non-script imports?
I have in my code this import:
The plugin complains and when "fixed", it changes that line into
I think that rule should only apply to some pattern, like
/.+(t|j)s(x)?/
by default. Possibly configurable.The text was updated successfully, but these errors were encountered: