Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
@codemirror/lint
Advanced tools
@codemirror/lint is a package for the CodeMirror 6 text editor that provides linting functionality. It allows developers to integrate custom linting logic into their CodeMirror instances, enabling real-time code analysis and error reporting.
Basic Linting
This code demonstrates how to set up a basic linter in a CodeMirror 6 editor. The `linter` function is used to create a custom linter, and `lintGutter` is used to display linting results in the editor's gutter.
const { linter, lintGutter } = require('@codemirror/lint');
const { EditorState, EditorView, basicSetup } = require('@codemirror/basic-setup');
const myLinter = linter(view => {
let diagnostics = [];
// Custom linting logic
return diagnostics;
});
const state = EditorState.create({
doc: 'const x = 10;',
extensions: [basicSetup, myLinter, lintGutter()]
});
const view = new EditorView({state, parent: document.body});
Custom Linting Logic
This code sample shows how to implement custom linting logic. The linter checks for the presence of the string 'foo' in the document and returns an error diagnostic if found.
const { linter } = require('@codemirror/lint');
const myLinter = linter(view => {
let diagnostics = [];
for (let {from, to, text} of view.state.doc.iterRange(0, view.state.doc.length)) {
if (text.includes('foo')) {
diagnostics.push({
from,
to,
severity: 'error',
message: 'Avoid using "foo"'
});
}
}
return diagnostics;
});
Linting with External Libraries
This example demonstrates how to integrate an external linting library, such as ESLint, with CodeMirror's linting system. The linter function uses ESLint to analyze the document and convert the results into CodeMirror diagnostics.
const { linter } = require('@codemirror/lint');
const { lint } = require('eslint');
const eslintLinter = linter(view => {
const results = lint(view.state.doc.toString());
return results.map(result => ({
from: result.range[0],
to: result.range[1],
severity: result.severity === 2 ? 'error' : 'warning',
message: result.message
}));
});
ESLint is a popular linting tool for JavaScript and TypeScript. It provides a wide range of rules and plugins for code quality and style enforcement. Unlike @codemirror/lint, which is specific to the CodeMirror editor, ESLint can be used in various environments, including command-line interfaces and build systems.
JSHint is another JavaScript linting tool that helps detect errors and potential problems in code. It is similar to ESLint but has a different set of rules and configurations. JSHint can be integrated into various editors and build systems, whereas @codemirror/lint is specifically designed for use with CodeMirror.
Stylelint is a linter for CSS and other style sheet languages. It helps enforce consistent conventions and catch errors in stylesheets. While @codemirror/lint focuses on providing a linting framework for CodeMirror, Stylelint is specialized for style sheet linting and can be used in different environments.
[ WEBSITE | DOCS | ISSUES | FORUM | CHANGELOG ]
This package implements linting support for the CodeMirror code editor.
The project page has more information, a number of examples and the documentation.
This code is released under an MIT license.
We aim to be an inclusive, welcoming community. To make that explicit, we have a code of conduct that applies to communication around the project.
6.2.0 (2023-02-27)
The new needsRefresh
option to linter
makes it possible to cause linting to be recalculated for non-document state changes.
FAQs
Linting support for the CodeMirror code editor
The npm package @codemirror/lint receives a total of 804,270 weekly downloads. As such, @codemirror/lint popularity was classified as popular.
We found that @codemirror/lint demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.