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
258
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.3 to 0.1.4

dist/src/writers.d.ts

77

dist/src/index.js

@@ -12,3 +12,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const chalk = require("chalk");
const fs = require("fs");

@@ -23,2 +22,4 @@ const glob = require("glob");

const vscode_uri_1 = require("vscode-uri");
const writers_1 = require("./writers");
const outputFormats = ["human", "human-verbose", "machine"];
/* eslint-disable @typescript-eslint/no-empty-function */

@@ -51,23 +52,5 @@ class NullLogger {

}
function logDiagnostic(diagnostic, text) {
const source = diagnostic.source ? `(${diagnostic.source})` : '';
// eslint-disable-next-line max-len
const position = `Line: ${diagnostic.range.start.line}, Character: ${diagnostic.range.start.character}`;
// Show some context around diagnostic range
const startOffset = svelte_language_server_1.offsetAt(diagnostic.range.start, text);
const endOffset = svelte_language_server_1.offsetAt(diagnostic.range.end, text);
const codePrev = chalk.cyan(text.substring(Math.max(startOffset - 10, 0), startOffset));
const codeHighlight = chalk.magenta(text.substring(startOffset, endOffset));
const codePost = chalk.cyan(text.substring(endOffset, endOffset + 10));
const code = codePrev + codeHighlight + codePost;
const msg = `${diagnostic.message} ${source}\n${position}\n${chalk.cyan(code)}`;
if (diagnostic.severity === vscode_languageserver_protocol_1.DiagnosticSeverity.Error) {
console.log(`${chalk.red('Error')}: ${msg}`);
return 1;
}
console.log(`${chalk.yellow('Warn')} : ${msg}`);
return 0;
}
function getDiagnostics(workspaceUri) {
function getDiagnostics(workspaceUri, writer) {
return __awaiter(this, void 0, void 0, function* () {
writer.start(workspaceUri.fsPath);
const clientConnection = yield prepareClientConnection();

@@ -79,4 +62,7 @@ const files = glob.sync('**/*.svelte', {

const absFilePaths = files.map((f) => path.resolve(workspaceUri.fsPath, f));
console.log('');
let errCount = 0;
const result = {
fileCount: absFilePaths.length,
errorCount: 0,
warningCount: 0
};
for (const absFilePath of absFilePaths) {

@@ -92,18 +78,25 @@ const text = fs.readFileSync(absFilePath, 'utf-8');

});
let res = [];
try {
const res = (yield clientConnection.sendRequest('$/getDiagnostics', {
res = (yield clientConnection.sendRequest('$/getDiagnostics', {
uri: vscode_uri_1.URI.file(absFilePath).toString(),
}));
if (res.length > 0) {
console.log('');
console.log(`${chalk.green('File')} : ${chalk.green(absFilePath)}`);
res.forEach((d) => (errCount += logDiagnostic(d, text)));
console.log('');
}
}
catch (err) {
console.log(err);
writer.failure(err);
return null;
}
// eslint-disable-next-line max-len
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;
}
});
}
return errCount;
writer.completion(result.fileCount, result.errorCount, result.warningCount);
return result;
});

@@ -119,20 +112,20 @@ }

}
console.log(`Loading svelte-check in workspace path: ${workspacePath}`);
workspaceUri = vscode_uri_1.URI.file(workspacePath);
}
else {
console.log(`Loading svelte-check in current directory: ${process.cwd()}`);
workspaceUri = vscode_uri_1.URI.file(process.cwd());
}
console.log('');
console.log('Getting Svelte diagnostics...');
console.log('====================================');
const errCount = yield getDiagnostics(workspaceUri);
console.log('====================================');
if (errCount === 0) {
console.log(chalk.green(`svelte-check found no errors`));
const outputFormat = outputFormats.includes(myArgs['output']) ? myArgs['output'] : "human-verbose";
let writer;
if (outputFormat === "human-verbose" || outputFormat === "human") {
writer = new writers_1.HumanFriendlyWriter(process.stdout, outputFormat === "human-verbose");
}
else {
writer = new writers_1.MachineFriendlyWriter(process.stdout);
}
const result = yield getDiagnostics(workspaceUri, writer);
if (result && result.errorCount === 0) {
process.exit(0);
}
else {
console.log(chalk.red(`svelte-check found ${errCount} ${errCount === 1 ? 'error' : 'errors'}`));
process.exit(1);

@@ -139,0 +132,0 @@ }

@@ -1,1 +0,1 @@

{"name":"svelte-check","description":"Svelte Code Checker Terminal Interface","version":"0.1.3","main":"./dist/src/index.js","bin":"./bin/svelte-check","author":"The Svelte Community","license":"MIT","dependencies":{"chalk":"^4.0.0","glob":"^7.1.6","minimist":"^1.2.5","svelte-language-server":"*","vscode-languageserver":"6.1.1","vscode-languageserver-protocol":"3.15.3","vscode-languageserver-types":"3.15.1","vscode-uri":"2.1.1"},"scripts":{"build":"tsc","test":"npm --version"},"devDependencies":{"@types/glob":"^7.1.1","@types/minimist":"^1.2.0","typescript":"*"}}
{"name":"svelte-check","description":"Svelte Code Checker Terminal Interface","version":"0.1.4","main":"./dist/src/index.js","bin":"./bin/svelte-check","author":"The Svelte Community","license":"MIT","dependencies":{"chalk":"^4.0.0","glob":"^7.1.6","minimist":"^1.2.5","svelte-language-server":"*","vscode-languageserver":"6.1.1","vscode-languageserver-protocol":"3.15.3","vscode-languageserver-types":"3.15.1","vscode-uri":"2.1.1"},"scripts":{"build":"tsc","test":"npm --version"},"devDependencies":{"@types/glob":"^7.1.1","@types/minimist":"^1.2.0","typescript":"*"}}

@@ -52,1 +52,49 @@ # Check your code with svelte-check

`--workspace <path to your workspace, where checking starts>`
`--outputFormat <human|human-verbose|machine>`
### Machine-Readable Output
Setting the `--outputFormat` to `machine` will format output in a way that is easier to read
by machines, e.g. inside CI pipelines, for code quality checks, ets.
Each row corresponds to a new record. Rows are made up of columns that are separated by a
single space character. The first column of every row contains a timestamp in milliseconds
which can be used for monitoring purposes. The second columns gives us the "row type", based
on which the number and types of subsequent columns may differ.
The first row is of type `START` and contains the workspace folder (wrapped in quotes).
Example:
```
1590680325583 START "/home/user/language-tools/packages/language-server/test/plugins/typescript/testfiles"
```
Any number of `ERROR` or `WARNING` records may follow. Their structure is identical and tells
us the filename, the line and column numbers, and the error message. The filename is relative
to the workspace directory. The filename and the message are both wrapped in quotes.
Example:
```
1590680326283 ERROR "codeactions.svelte" 1:16 "Cannot find module 'blubb' or its corresponding type declarations."
1590680326778 WARNING "imported-file.svelte" 0:37 "Component has unused export property 'prop'. If it is for external reference only, please consider using `export const prop`"
```
The output concludes with a `COMPLETED` message that summarizes total numbers of files, errors,
and warnings that were encountered during the check.
Example:
```
1590680326807 COMPLETED 20 FILES 21 ERRORS 1 WARNINGS
```
If the application experiences a runtime error, this error will appear as a `FAILURE` record.
Example:
```
1590680328921 FAILURE "Connection closed"
```

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