Socket
Socket
Sign inDemoInstall

@codemirror/lint

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codemirror/lint - npm Package Compare versions

Comparing version 0.20.1 to 0.20.2

8

CHANGELOG.md

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

## 0.20.2 (2022-05-02)
### New features
The package now exports the `LintSource` function type.
The new `markerFilter` and `tooltipFilter` options to `linter` and `lintGutter` allow more control over which diagnostics are visible and which have tooltips.
## 0.20.1 (2022-04-22)

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

41

dist/index.d.ts

@@ -54,2 +54,20 @@ import * as _codemirror_state from '@codemirror/state';

}
declare type DiagnosticFilter = (diagnostics: readonly Diagnostic[]) => Diagnostic[];
interface LintConfig {
/**
Time to wait (in milliseconds) after a change before running
the linter. Defaults to 750ms.
*/
delay?: number;
/**
Optional filter to determine which diagnostics produce markers
in the content.
*/
markerFilter?: null | DiagnosticFilter;
/**
Filter applied to a set of diagnostics shown in a tooltip. No
tooltip will appear if the empty set is returned.
*/
tooltipFilter?: null | DiagnosticFilter;
}
interface LintGutterConfig {

@@ -60,2 +78,12 @@ /**

hoverTime?: number;
/**
Optional filter determining which diagnostics show a marker in
the gutter.
*/
markerFilter?: null | DiagnosticFilter;
/**
Optional filter for diagnostics displayed in a tooltip, which
can also be used to prevent a tooltip appearing.
*/
tooltipFilter?: null | DiagnosticFilter;
}

@@ -96,2 +124,5 @@ /**

declare const lintKeymap: readonly KeyBinding[];
/**
The type of a function that produces diagnostics.
*/
declare type LintSource = (view: EditorView) => readonly Diagnostic[] | Promise<readonly Diagnostic[]>;

@@ -103,9 +134,3 @@ /**

*/
declare function linter(source: LintSource, config?: {
/**
Time to wait (in milliseconds) after a change before running
the linter. Defaults to 750ms.
*/
delay?: number;
}): Extension;
declare function linter(source: LintSource, config?: LintConfig): Extension;
/**

@@ -123,2 +148,2 @@ Forces any linters [configured](https://codemirror.net/6/docs/ref/#lint.linter) to run when the

export { Action, Diagnostic, closeLintPanel, diagnosticCount, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
export { Action, Diagnostic, LintSource, closeLintPanel, diagnosticCount, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };

53

dist/index.js
import { Decoration, showPanel, EditorView, ViewPlugin, hoverTooltip, logException, gutter, showTooltip, getPanel, WidgetType, GutterMarker } from '@codemirror/view';
import { StateEffect, StateField, Facet, RangeSet, combineConfig } from '@codemirror/state';
import { StateEffect, StateField, Facet, combineConfig, RangeSet } from '@codemirror/state';
import elt from 'crelt';

@@ -19,3 +19,8 @@

static init(diagnostics, panel, state) {
let ranges = Decoration.set(diagnostics.map((d) => {
// Filter the list of diagnostics for which to create markers
let markedDiagnostics = diagnostics;
let diagnosticFilter = state.facet(lintConfig).markerFilter;
if (diagnosticFilter)
markedDiagnostics = diagnosticFilter(markedDiagnostics);
let ranges = Decoration.set(markedDiagnostics.map((d) => {
// For zero-length ranges or ranges covering only a line break, create a widget

@@ -126,2 +131,5 @@ return d.from == d.to || (d.from == d.to - 1 && state.doc.lineAt(d.from).to == d.from)

});
let diagnosticFilter = view.state.facet(lintConfig).tooltipFilter;
if (diagnosticFilter)
found = diagnosticFilter(found);
if (!found.length)

@@ -194,3 +202,3 @@ return null;

this.set = true;
let { delay } = view.state.facet(lintSource);
let { delay } = view.state.facet(lintConfig);
this.lintTime = Date.now() + delay;

@@ -207,3 +215,3 @@ this.run = this.run.bind(this);

this.set = false;
let { state } = this.view, { sources } = state.facet(lintSource);
let { state } = this.view, { sources } = state.facet(lintConfig);
Promise.all(sources.map(source => Promise.resolve(source(this.view)))).then(annotations => {

@@ -217,8 +225,8 @@ let all = annotations.reduce((a, b) => a.concat(b));

update(update) {
let source = update.state.facet(lintSource);
if (update.docChanged || source != update.startState.facet(lintSource)) {
this.lintTime = Date.now() + source.delay;
let config = update.state.facet(lintConfig);
if (update.docChanged || config != update.startState.facet(lintConfig)) {
this.lintTime = Date.now() + config.delay;
if (!this.set) {
this.set = true;
this.timeout = setTimeout(this.run, source.delay);
this.timeout = setTimeout(this.run, config.delay);
}

@@ -237,5 +245,9 @@ }

});
const lintSource = /*@__PURE__*/Facet.define({
const lintConfig = /*@__PURE__*/Facet.define({
combine(input) {
return { sources: input.map(i => i.source), delay: input.length ? Math.max(...input.map(i => i.delay)) : 750 };
return Object.assign({ sources: input.map(i => i.source) }, combineConfig(input.map(i => i.config), {
delay: 750,
markerFilter: null,
tooltipFilter: null
}));
},

@@ -250,4 +262,3 @@ enables: lintPlugin

function linter(source, config = {}) {
var _a;
return lintSource.of({ source, delay: (_a = config.delay) !== null && _a !== void 0 ? _a : 750 });
return lintConfig.of({ source, config });
}

@@ -590,3 +601,8 @@ /**

elt.className = "cm-lint-marker cm-lint-marker-" + this.severity;
elt.onmouseover = () => gutterMarkerMouseOver(view, elt, this.diagnostics);
let diagnostics = this.diagnostics;
let diagnosticsFilter = view.state.facet(lintGutterConfig).tooltipFilter;
if (diagnosticsFilter)
diagnostics = diagnosticsFilter(diagnostics);
if (diagnostics.length)
elt.onmouseover = () => gutterMarkerMouseOver(view, elt, diagnostics);
return elt;

@@ -663,6 +679,11 @@ }

markers = markers.map(tr.changes);
for (let effect of tr.effects)
let diagnosticFilter = tr.state.facet(lintGutterConfig).markerFilter;
for (let effect of tr.effects) {
if (effect.is(setDiagnosticsEffect)) {
markers = markersForDiagnostics(tr.state.doc, effect.value);
let diagnostics = effect.value;
if (diagnosticFilter)
diagnostics = diagnosticFilter(diagnostics || []);
markers = markersForDiagnostics(tr.state.doc, diagnostics.slice(0));
}
}
return markers;

@@ -706,2 +727,4 @@ }

hoverTime: 300 /* Time */,
markerFilter: null,
tooltipFilter: null
});

@@ -708,0 +731,0 @@ }

{
"name": "@codemirror/lint",
"version": "0.20.1",
"version": "0.20.2",
"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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc