Skip to content

Commit

Permalink
Lint on files directly
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscerie committed Mar 23, 2024
1 parent f75516e commit b109c2d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 80 deletions.
36 changes: 2 additions & 34 deletions selene-vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions selene-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,9 @@
},
"dependencies": {
"fs-write-stream-atomic": "^1.0.10",
"minimatch": "^9.0.3",
"request": "^2.88.2",
"request-promise-native": "^1.0.8",
"semver": "^7.3.8",
"toml": "^3.0.0",
"unzipper": "^0.10.11"
}
}
48 changes: 4 additions & 44 deletions selene-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import * as selene from "./selene"
import * as timers from "timers"
import * as util from "./util"
import * as vscode from "vscode"
import * as path from "path"
import * as fs from "fs"
import * as toml from "toml"
import { minimatch } from "minimatch"
import { Diagnostic, Severity, Label } from "./structures/diagnostic"
import { Output } from "./structures/output"
import { lintConfig } from "./configLint"
Expand Down Expand Up @@ -151,49 +147,13 @@ export async function activate(
return
}

const workspaceFolder = vscode.workspace.getWorkspaceFolder(
document.uri,
)
const workspaceRoot = workspaceFolder?.uri.fsPath
if (!workspaceRoot) {
console.error("Failed to find workspace root")
return
}

const configPath = path.join(workspaceRoot, "selene.toml")
let config
try {
const configFileContent = fs.readFileSync(configPath, "utf-8")
config = toml.parse(configFileContent)
} catch (error) {
console.error(`Error parsing config file: ${error}`)
return
}

const excludeGlobs = config?.exclude || []
const shouldExclude = excludeGlobs.some((pattern: string) => {
// Document path given is absolute so the patterns should be as well
// If multiple `selene.toml` becomes supported, this will likely need to be changed to support it.
const excludeGlobAbsolute = path.isAbsolute(pattern)
? pattern
: path.join(workspaceRoot, pattern)

return minimatch(
document.uri.fsPath.replace(/\\/g, "/"),
excludeGlobAbsolute.replace(/\\/g, "/"),
)
})

if (shouldExclude) {
return
}

const output = await selene.seleneCommand(
context.globalStorageUri,
"--display-style=json2 --no-summary -",
// Must use relative path for now due to https://github.com/Kampfkarren/selene/issues/593
"--display-style=json2 --no-summary " +
vscode.workspace.asRelativePath(document.uri.fsPath),
selene.Expectation.Stderr,
workspaceFolder,
document.getText(),
vscode.workspace.getWorkspaceFolder(document.uri),
)

if (!output) {
Expand Down

0 comments on commit b109c2d

Please sign in to comment.