eslint-plugin-unused-imports
Advanced tools
Comparing version 1.0.3 to 1.1.0
@@ -7,14 +7,11 @@ /** | ||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
const noUnusedVars = require("./rules/no-unused-vars"); | ||
const noUnusedImports = require("./rules/no-unused-imports"); | ||
var requireIndex = require("requireindex"); | ||
//------------------------------------------------------------------------------ | ||
// Plugin Definition | ||
//------------------------------------------------------------------------------ | ||
// import all rules in lib/rules | ||
module.exports.rules = requireIndex(__dirname + "/rules"); | ||
module.exports.rules = { | ||
"no-unused-vars": noUnusedVars, | ||
"no-unused-imports": noUnusedImports, | ||
"no-unused-vars-ts": noUnusedVars, | ||
"no-unused-imports-ts": noUnusedImports, | ||
}; |
@@ -10,7 +10,14 @@ /** | ||
const ruleComposer = require("eslint-rule-composer"); | ||
const eslint = require("eslint"); | ||
const rule = new eslint.Linter().getRules().get("no-unused-vars"); | ||
let rule; | ||
try { | ||
const tslint = require("@typescript-eslint/eslint-plugin"); | ||
rule = tslint.rules["no-unused-vars"]; | ||
} catch (_) { | ||
const eslint = require("eslint"); | ||
rule = new eslint.Linter().getRules().get("no-unused-vars"); | ||
} | ||
rule.meta.fixable = "code"; | ||
module.exports = ruleComposer.filterReports(rule, unusedImportsPredicate); |
@@ -10,7 +10,14 @@ /** | ||
const ruleComposer = require("eslint-rule-composer"); | ||
const eslint = require("eslint"); | ||
const rule = new eslint.Linter().getRules().get("no-unused-vars"); | ||
let rule; | ||
try { | ||
const tslint = require("@typescript-eslint/eslint-plugin"); | ||
rule = tslint.rules["no-unused-vars"]; | ||
} catch (_) { | ||
const eslint = require("eslint"); | ||
rule = new eslint.Linter().getRules().get("no-unused-vars"); | ||
} | ||
rule.meta.fixable = "code"; | ||
module.exports = ruleComposer.filterReports(rule, unusedVarsPredicate); |
@@ -52,3 +52,3 @@ exports.unusedVarsPredicate = (problem, context) => { | ||
fixer.remove(grandParent), | ||
fixer.replaceTextRange([grandParent.range[1], nextToken.range[0]], "\n".repeat(count)) | ||
fixer.replaceTextRange([grandParent.range[1], nextToken.range[0]], "\n".repeat(count)), | ||
]; | ||
@@ -55,0 +55,0 @@ } |
{ | ||
"name": "eslint-plugin-unused-imports", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Report and remove unused es6 modules", | ||
@@ -17,4 +17,3 @@ "keywords": [ | ||
"dependencies": { | ||
"eslint-rule-composer": "^0.3.0", | ||
"requireindex": "~1.2.0" | ||
"eslint-rule-composer": "^0.3.0" | ||
}, | ||
@@ -21,0 +20,0 @@ "devDependencies": { |
@@ -5,10 +5,11 @@ # eslint-plugin-unused-imports | ||
## _Important for version 1.1_ | ||
The `-ts` rules are deprecated, the package now looks for `@typescript-eslint/eslint-plugin` to exist to decide between the typescript and eslint version. | ||
The `-ts` rule will still work, but point to the new rule instead. | ||
## Typescript | ||
If running [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint) please use the `-ts` | ||
extension on your rules to make this also leverage type information (otherwise the autofixer will remove | ||
imports only used for type information). There is an example in the Usage section below. | ||
If running typescript with [@typescript-eslint](https://github.com/typescript-eslint/typescript-eslint) make sure to use both `@typescript-eslint/eslint-plugin` and `@typescript-eslint/parser`. | ||
_For typescript [@typescript-eslint](https://github.com/typescript-eslint/typescript-eslint) is also needed!_ | ||
## React | ||
@@ -49,3 +50,3 @@ | ||
"rules": { | ||
"no-unused-vars": "off", | ||
"no-unused-vars": "off", // or "@typescript-eslint/no-unused-vars": "off", | ||
"unused-imports/no-unused-imports": "error", | ||
@@ -60,17 +61,2 @@ "unused-imports/no-unused-vars": [ | ||
Or, if using TypeScript: | ||
```json | ||
{ | ||
"rules": { | ||
"@typescript-eslint/no-unused-vars": "off", | ||
"unused-imports/no-unused-imports-ts": "error", | ||
"unused-imports/no-unused-vars-ts": [ | ||
"warn", | ||
{ "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" } | ||
] | ||
} | ||
} | ||
``` | ||
## Supported Rules | ||
@@ -80,3 +66,1 @@ | ||
- `no-unused-vars` | ||
- `no-unused-imports-ts` | ||
- `no-unused-vars-ts` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
8129
9
119
63
- Removedrequireindex@~1.2.0
- Removedrequireindex@1.2.0(transitive)