Socket
Socket
Sign inDemoInstall

@codemirror/lint

Package Overview
Dependencies
3
Maintainers
2
Versions
36
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codemirror/lint


Version published
Weekly downloads
969K
decreased by-16.45%
Maintainers
2
Install size
1.61 MB
Created
Weekly downloads
 

Package description

What is @codemirror/lint?

@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.

What are @codemirror/lint's main functionalities?

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
  }));
});

Other packages similar to @codemirror/lint

Changelog

Source

6.8.1 (2024-06-19)

Bug fixes

Make lint markers non-inclusive again, since having them that way causes more issues than it solves.

Readme

Source

@codemirror/lint NPM version

[ 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.

Keywords

FAQs

Last updated on 19 Jun 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc