Skip to content

Commit

Permalink
feat: disable all rules for file. close #14.
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjiaxuan committed Mar 21, 2023
1 parent 1ba121a commit 5a611ac
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
](https://marketplace.visualstudio.com/items?itemName=lvjiaxuan.eslint-disable)

## Features
Select single or **multiple lines** which have rule problems from the extension of ESLint IntelliSense, and it could either disable rules for lines by `ctrl + alt + d` or disable for the entire file by `ctrl + alt + e`.
1. Select single or **multiple lines** which have rule problems from the extension of ESLint IntelliSense, and it could either disable rules for lines by `ctrl + alt + d` or disable for the entire file by `ctrl + alt + e`.
2. Disable all problem rules by `ctrl + alt + a`.


> **Note**
Expand All @@ -33,6 +34,7 @@ For single line.


For multiple lines, press `ctrl + d` to select another pair in other side.

![multiple](assets/2.gif)

## TODO
Expand Down
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
{
"command": "eslint-disable.entire",
"title": "eslint-disable: disable for entire file"
},
{
"command": "eslint-disable.all",
"title": "eslint-disable: disable all rules for entire file"
}
],
"menus": {
Expand All @@ -44,6 +48,10 @@
{
"command": "eslint-disable.entire",
"group": "1_modification"
},
{
"command": "eslint-disable.all",
"group": "1_modification"
}
]
},
Expand All @@ -59,6 +67,12 @@
"key": "ctrl+alt+e",
"mac": "ctrl+alt+e",
"when": "editorTextFocus"
},
{
"command": "eslint-disable.all",
"key": "ctrl+alt+a",
"mac": "ctrl+alt+a",
"when": "editorTextFocus"
}
]
},
Expand Down
29 changes: 19 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import path from 'node:path'
export function activate(context: ExtensionContext) {

context.subscriptions.push(disableForLines)
context.subscriptions.push(disableForEntire)
context.subscriptions.push(disableForFile)
context.subscriptions.push(disableAllForFile)
}

export function deactivate() {
disableForLines.dispose()
disableForEntire.dispose()
disableForFile.dispose()
disableAllForFile.dispose()
}

const disableForLines = commands.registerCommand('eslint-disable.disable', () => {
Expand Down Expand Up @@ -61,22 +63,24 @@ const disableForLines = commands.registerCommand('eslint-disable.disable', () =>
}
})

const disableForEntire = commands.registerCommand('eslint-disable.entire', async () => {
const disableForFile = commands.registerCommand('eslint-disable.entire', async (allRules: false) => {
const result = getESLintDiagnostics()
if (!result) {
return
}

const { text, selection, activeTextEditor, eslintDiagnostics } = result
const { selection, activeTextEditor, eslintDiagnostics } = result

// @ts-ignore
let insertRules: Set<string> = eslintDiagnostics.reduce((insertRules, item) => {
let insertRules = eslintDiagnostics.reduce((insertRules, item) => {

const isRuleInLine = selection.isSingleLine
? item.range.start.line === selection.start.line
: selection.start.line + 1 <= item.range.start.line && item.range.start.line <= selection.end.line + 1
let isAlwaysAdd: boolean = allRules
if (!isAlwaysAdd) {
isAlwaysAdd = selection.isSingleLine
? item.range.start.line === selection.start.line
: selection.start.line + 1 <= item.range.start.line && item.range.start.line <= selection.end.line + 1
}

if (isRuleInLine) {
if (isAlwaysAdd) {
// @ts-ignore
insertRules.add(item.code.value as string)
}
Expand Down Expand Up @@ -128,6 +132,11 @@ const disableForEntire = commands.registerCommand('eslint-disable.entire', async
}
})

const disableAllForFile = commands.registerCommand('eslint-disable.all', () => {
// ...
void commands.executeCommand('eslint-disable.entire', true)
})

function getESLintDiagnostics() {
const { activeTextEditor } = window

Expand Down

0 comments on commit 5a611ac

Please sign in to comment.