Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@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

Linting support for the CodeMirror code editor

  • 0.19.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
550K
decreased by-58.23%
Maintainers
2
Weekly downloads
 
Created

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

Keywords

FAQs

Package last updated on 25 Feb 2022

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc