Socket
Socket
Sign inDemoInstall

@codemirror/lint

Package Overview
Dependencies
9
Maintainers
2
Versions
36
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.18.3 to 0.18.4

8

CHANGELOG.md

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

## 0.18.4 (2021-06-07)
### Bug fixes
Multiple `linter` extensions can now be added to an editor without disrupting each other.
Fix poor layout on lint tooltips due to changes in @codemirror/tooltip.
## 0.18.3 (2021-05-10)

@@ -2,0 +10,0 @@

3

dist/index.d.ts

@@ -77,2 +77,3 @@ import { EditorView, Command, KeyBinding } from '@codemirror/view';

declare const lintKeymap: readonly KeyBinding[];
declare type LintSource = (view: EditorView) => readonly Diagnostic[] | Promise<readonly Diagnostic[]>;
/**

@@ -83,3 +84,3 @@ Given a diagnostic source, this function returns an extension that

*/
declare function linter(source: (view: EditorView) => readonly Diagnostic[] | Promise<readonly Diagnostic[]>, config?: {
declare function linter(source: LintSource, config?: {
/**

@@ -86,0 +87,0 @@ Time to wait (in milliseconds) after a change before running

import { EditorView, Decoration, ViewPlugin, logException, WidgetType } from '@codemirror/view';
import { StateEffect, StateField } from '@codemirror/state';
import { StateEffect, StateField, Facet } from '@codemirror/state';
import { hoverTooltip } from '@codemirror/tooltip';

@@ -31,3 +31,3 @@ import { showPanel, getPanel } from '@codemirror/panel';

}).range(d.from);
}));
}), true);
return new LintState(ranges, panel, findDiagnostic(ranges));

@@ -171,2 +171,49 @@ }

];
const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
constructor(view) {
this.view = view;
this.timeout = -1;
this.set = true;
let { delay } = view.state.facet(lintSource);
this.lintTime = Date.now() + delay;
this.run = this.run.bind(this);
this.timeout = setTimeout(this.run, delay);
}
run() {
let now = Date.now();
if (now < this.lintTime - 10) {
setTimeout(this.run, this.lintTime - now);
}
else {
this.set = false;
let { state } = this.view, { sources } = state.facet(lintSource);
Promise.all(sources.map(source => Promise.resolve(source(this.view)))).then(annotations => {
var _a, _b;
let all = annotations.reduce((a, b) => a.concat(b));
if (this.view.state.doc == state.doc &&
(all.length || ((_b = (_a = this.view.state.field(lintState, false)) === null || _a === void 0 ? void 0 : _a.diagnostics) === null || _b === void 0 ? void 0 : _b.size)))
this.view.dispatch(setDiagnostics(this.view.state, all));
}, error => { logException(this.view.state, error); });
}
}
update(update) {
if (update.docChanged) {
let { delay } = update.state.facet(lintSource);
this.lintTime = Date.now() + delay;
if (!this.set) {
this.set = true;
this.timeout = setTimeout(this.run, delay);
}
}
}
destroy() {
clearTimeout(this.timeout);
}
});
const lintSource = /*@__PURE__*/Facet.define({
combine(input) {
return { sources: input.map(i => i.source), delay: input.length ? Math.max(...input.map(i => i.delay)) : 750 };
},
enables: lintPlugin
});
/**

@@ -179,37 +226,3 @@ Given a diagnostic source, this function returns an extension that

var _a;
let delay = (_a = config.delay) !== null && _a !== void 0 ? _a : 750;
return ViewPlugin.fromClass(class {
constructor(view) {
this.view = view;
this.lintTime = Date.now() + delay;
this.set = true;
this.run = this.run.bind(this);
setTimeout(this.run, delay);
}
run() {
let now = Date.now();
if (now < this.lintTime - 10) {
setTimeout(this.run, this.lintTime - now);
}
else {
this.set = false;
let { state } = this.view;
Promise.resolve(source(this.view)).then(annotations => {
var _a, _b;
if (this.view.state.doc == state.doc &&
(annotations.length || ((_b = (_a = this.view.state.field(lintState, false)) === null || _a === void 0 ? void 0 : _a.diagnostics) === null || _b === void 0 ? void 0 : _b.size)))
this.view.dispatch(setDiagnostics(this.view.state, annotations));
}, error => { logException(this.view.state, error); });
}
}
update(update) {
if (update.docChanged) {
this.lintTime = Date.now() + delay;
if (!this.set) {
this.set = true;
setTimeout(this.run, delay);
}
}
}
});
return lintSource.of({ source, delay: (_a = config.delay) !== null && _a !== void 0 ? _a : 750 });
}

@@ -477,2 +490,6 @@ function assignKeys(actions) {

".cm-lintRange-active": { backgroundColor: "#ffdd9980" },
".cm-tooltip-lint": {
padding: 0,
margin: 0
},
".cm-lintPoint": {

@@ -479,0 +496,0 @@ position: "relative",

{
"name": "@codemirror/lint",
"version": "0.18.3",
"version": "0.18.4",
"description": "Linting support for the CodeMirror code editor",

@@ -5,0 +5,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc