Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svelte-check

Package Overview
Dependencies
Maintainers
1
Versions
264
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-check - npm Package Compare versions

Comparing version 0.1.59 to 1.0.0

109

dist/src/index.js

@@ -14,43 +14,76 @@ "use strict";

const writers_1 = require("./writers");
const chokidar_1 = require("chokidar");
const outputFormats = ['human', 'human-verbose', 'machine'];
async function getDiagnostics(workspaceUri, writer) {
writer.start(workspaceUri.fsPath);
const svelteCheck = new svelte_language_server_1.SvelteCheck(workspaceUri.fsPath);
function openAllDocuments(workspaceUri, filePathsToIgnore, svelteCheck) {
const files = glob.sync('**/*.svelte', {
cwd: workspaceUri.fsPath,
ignore: ['node_modules/**'],
ignore: ['node_modules/**'].concat(filePathsToIgnore.map((ignore) => `${ignore}/**`)),
});
const absFilePaths = files.map((f) => path.resolve(workspaceUri.fsPath, f));
const result = {
fileCount: absFilePaths.length,
errorCount: 0,
warningCount: 0,
};
for (const absFilePath of absFilePaths) {
const text = fs.readFileSync(absFilePath, 'utf-8');
let res = [];
try {
res = await svelteCheck.getDiagnostics({
uri: vscode_uri_1.URI.file(absFilePath).toString(),
text,
svelteCheck.upsertDocument({
uri: vscode_uri_1.URI.file(absFilePath).toString(),
text,
});
}
}
async function getDiagnostics(workspaceUri, writer, svelteCheck) {
writer.start(workspaceUri.fsPath);
try {
const diagnostics = await svelteCheck.getDiagnostics();
const result = {
fileCount: diagnostics.length,
errorCount: 0,
warningCount: 0,
};
for (const diagnostic of diagnostics) {
writer.file(diagnostic.diagnostics, workspaceUri.fsPath, path.relative(workspaceUri.fsPath, diagnostic.filePath), diagnostic.text);
diagnostic.diagnostics.forEach((d) => {
if (d.severity === vscode_languageserver_protocol_1.DiagnosticSeverity.Error) {
result.errorCount += 1;
}
else if (d.severity === vscode_languageserver_protocol_1.DiagnosticSeverity.Warning) {
result.warningCount += 1;
}
});
}
catch (err) {
writer.failure(err);
return null;
}
writer.file(res, workspaceUri.fsPath, path.relative(workspaceUri.fsPath, absFilePath), text);
res.forEach((d) => {
if (d.severity === vscode_languageserver_protocol_1.DiagnosticSeverity.Error) {
result.errorCount += 1;
}
else if (d.severity === vscode_languageserver_protocol_1.DiagnosticSeverity.Warning) {
result.warningCount += 1;
}
});
writer.completion(result.fileCount, result.errorCount, result.warningCount);
return result;
}
writer.completion(result.fileCount, result.errorCount, result.warningCount);
return result;
catch (err) {
writer.failure(err);
return null;
}
}
class DiagnosticsWatcher {
constructor(workspaceUri, svelteCheck, writer, filePathsToIgnore) {
this.workspaceUri = workspaceUri;
this.svelteCheck = svelteCheck;
this.writer = writer;
chokidar_1.watch(`${workspaceUri.fsPath}/**/*.svelte`, {
ignored: ['node_modules']
.concat(filePathsToIgnore)
.map((ignore) => path.join(workspaceUri.fsPath, ignore)),
})
.on('add', (path) => this.updateDocument(path))
.on('unlink', (path) => this.removeDocument(path))
.on('change', (path) => this.updateDocument(path));
}
updateDocument(path) {
const text = fs.readFileSync(path, 'utf-8');
this.svelteCheck.upsertDocument({ text, uri: vscode_uri_1.URI.file(path).toString() });
this.scheduleDiagnostics();
}
removeDocument(path) {
this.svelteCheck.removeDocument(vscode_uri_1.URI.file(path).toString());
this.scheduleDiagnostics();
}
scheduleDiagnostics() {
clearTimeout(this.updateDiagnostics);
this.updateDiagnostics = setTimeout(() => getDiagnostics(this.workspaceUri, this.writer, this.svelteCheck), 1000);
}
}
(async () => {
var _a;
const myArgs = argv(process.argv.slice(1));

@@ -78,8 +111,18 @@ let workspaceUri;

}
const result = await getDiagnostics(workspaceUri, writer);
if (result && result.errorCount === 0) {
process.exit(0);
const svelteCheck = new svelte_language_server_1.SvelteCheck(workspaceUri.fsPath);
const filePathsToIgnore = ((_a = myArgs['ignore']) === null || _a === void 0 ? void 0 : _a.split(' ')) || [];
if (myArgs['watch']) {
new DiagnosticsWatcher(workspaceUri, svelteCheck, writer, filePathsToIgnore);
}
else {
process.exit(1);
openAllDocuments(workspaceUri, filePathsToIgnore, svelteCheck);
const result = await getDiagnostics(workspaceUri, writer, svelteCheck);
if (result &&
result.errorCount === 0 &&
(!myArgs['fail-on-warnings'] || result.warningCount === 0)) {
process.exit(0);
}
else {
process.exit(1);
}
}

@@ -86,0 +129,0 @@ })().catch((_err) => {

/// <reference types="node" />
import { Writable } from "stream";
import { Writable } from 'stream';
import { Diagnostic } from 'vscode-languageserver-protocol';

@@ -16,3 +16,3 @@ export interface Writer {

file(diagnostics: Diagnostic[], workspaceDir: string, filename: string, text: string): void;
completion(_f: number, err: number, _w: number): void;
completion(_f: number, errorCount: number, warningCount: number): void;
failure(err: Error): void;

@@ -19,0 +19,0 @@ }

@@ -50,12 +50,15 @@ "use strict";

}
this.stream.write("\n");
this.stream.write('\n');
});
}
completion(_f, err, _w) {
completion(_f, errorCount, warningCount) {
this.stream.write('====================================\n');
if (err === 0) {
this.stream.write(chalk.green(`svelte-check found no errors\n`));
if (errorCount === 0 && warningCount === 0) {
this.stream.write(chalk.green(`svelte-check found no errors and no warnings\n`));
}
else if (errorCount === 0) {
this.stream.write(chalk.yellow(`svelte-check found ${warningCount} ${warningCount === 1 ? 'warning' : 'warnings'}\n`));
}
else {
this.stream.write(chalk.red(`svelte-check found ${err} ${err === 1 ? 'error' : 'errors'}\n`));
this.stream.write(chalk.red(`svelte-check found ${errorCount} ${errorCount === 1 ? 'error' : 'errors'} and ${warningCount} ${warningCount === 1 ? 'warning' : 'warnings'}\n`));
}

@@ -81,5 +84,7 @@ }

const { message, severity, range } = d;
const type = severity === vscode_languageserver_protocol_1.DiagnosticSeverity.Error ? "ERROR" :
severity === vscode_languageserver_protocol_1.DiagnosticSeverity.Warning ? "WARNING" :
null;
const type = severity === vscode_languageserver_protocol_1.DiagnosticSeverity.Error
? 'ERROR'
: severity === vscode_languageserver_protocol_1.DiagnosticSeverity.Warning
? 'WARNING'
: null;
if (type) {

@@ -86,0 +91,0 @@ const { line, character } = range.start;

{
"name": "svelte-check",
"description": "Svelte Code Checker Terminal Interface",
"version": "0.1.59",
"version": "1.0.0",
"main": "./dist/src/index.js",

@@ -23,2 +23,3 @@ "bin": "./bin/svelte-check",

"chalk": "^4.0.0",
"chokidar": "^3.4.1",
"glob": "^7.1.6",

@@ -25,0 +26,0 @@ "minimist": "^1.2.5",

@@ -57,2 +57,8 @@ # Check your code with svelte-check

`--watch` Will not exit after one pass but keep watching files for changes and rerun diagnostics.
`--ignore <files/folders to ignore, relative to workspace root, comma-separated. Example: --ignore dist,build>`
`--fail-on-warnings` Will also exit with error code when there are warnings
### More docs, preprocessor setup and troubleshooting

@@ -59,0 +65,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc