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

[no-var-requires] Recommendations do not show ES6 Modules example #899

Closed
ryanwilsonperkin opened this issue Aug 23, 2019 · 0 comments · Fixed by #900
Closed

[no-var-requires] Recommendations do not show ES6 Modules example #899

ryanwilsonperkin opened this issue Aug 23, 2019 · 0 comments · Fixed by #900
Labels
documentation Documentation ("docs") that needs adding/updating has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@ryanwilsonperkin
Copy link
Contributor

Repro

{
  "rules": {
    "@typescript-eslint/no-var-requires": ["error"]
  }
}
const Image = require("./image.svg");

Expected Result
Documentation includes an example about ES6 Modules. ie.

import Image from './image.svg';

Actual Result
Documentation only shows examples for typescript import foo = and require(...)

Additional Info
The documentation for no-var-requires explains that require code can be replaced by ES6 modules import syntax, but does not give an example of it.

We've recently added support for importing from SVG files using ES6 module import syntax (using a webpack loader), but some developers still write using the require syntax. When they do, they get the lint error which then instructs them to write in a different syntax than we support. While the docs do list ES6 modules as an option, they don't provide an example, which has confused some of our developers.

What I would love to see would be:

Examples of correct code for this rule:

import foo = require('foo');
require('foo');
+ import foo from 'foo';

Versions

package version
@typescript-eslint/eslint-plugin 1.10.2
@typescript-eslint/parser 1.10.2
TypeScript 3.2.2
ESLint 5.16.0
node 10.15.3
npm 6.4.1
@ryanwilsonperkin ryanwilsonperkin added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Aug 23, 2019
ryanwilsonperkin added a commit to ryanwilsonperkin/typescript-eslint that referenced this issue Aug 23, 2019
Fixes typescript-eslint#899 

Adds an example to the documentation for replacing `require` with ES6 modules. Since this isn't going to work on everyone's system, I'm happy to also add a comment on this line stating the restrictions if the maintainers of this think it would be appropriate.
@bradzacher bradzacher added documentation Documentation ("docs") that needs adding/updating has pr there is a PR raised to close this and removed triage Waiting for maintainers to take a look labels Aug 24, 2019
bradzacher pushed a commit that referenced this issue Aug 24, 2019
Fixes #899 

Adds an example to the documentation for replacing `require` with ES6 modules. Since this isn't going to work on everyone's system, I'm happy to also add a comment on this line stating the restrictions if the maintainers of this think it would be appropriate.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Documentation ("docs") that needs adding/updating has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants