Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
unified-lint-rule
Advanced tools
The `unified-lint-rule` package is a utility for creating linting rules for unified processors. Unified is a project that provides a suite of tools for processing content, such as Markdown and HTML, in a structured way. The `unified-lint-rule` package allows developers to define custom linting rules that can be used to enforce coding standards, catch errors, and ensure consistency in content processing.
Creating a Custom Lint Rule
This feature allows you to create a custom linting rule. In this example, the rule checks for the presence of the word 'foo' in text nodes and reports a message if it is found.
const rule = require('unified-lint-rule');
const visit = require('unist-util-visit');
const noFoo = rule('example/no-foo', (tree, file) => {
visit(tree, 'text', (node) => {
if (node.value.includes('foo')) {
file.message('Do not use the word "foo"', node);
}
});
});
module.exports = noFoo;
Integrating with Unified Processor
This feature demonstrates how to integrate a custom linting rule with a unified processor. The example shows how to use the `unified`, `remark-parse`, and `remark-lint` packages along with the custom `noFoo` rule to process a Markdown string and report any linting messages.
const unified = require('unified');
const markdown = require('remark-parse');
const lint = require('remark-lint');
const noFoo = require('./path-to-no-foo-rule');
unified()
.use(markdown)
.use(lint)
.use(noFoo)
.process('This is a foo test', (err, file) => {
if (err) throw err;
console.error(report(file));
});
ESLint is a widely-used linting tool for JavaScript and TypeScript. It allows developers to define and enforce coding standards and catch errors in their code. Unlike `unified-lint-rule`, which is specific to content processing with unified, ESLint is focused on JavaScript code quality and style.
Stylelint is a powerful linting tool for CSS and other style languages. It helps developers enforce consistent conventions and avoid errors in their stylesheets. While `unified-lint-rule` is used for content processing, Stylelint is specifically designed for linting styles.
Remark-lint is a collection of linting rules for Markdown files, built on top of the unified ecosystem. It provides a set of predefined rules for Markdown content, similar to how `unified-lint-rule` allows for custom rule creation. Remark-lint is more focused on Markdown-specific linting.
unified plugin to make it a bit easier to create linting rules.
Each rule in remark-lint
uses this project, so see that for examples!
This package is ESM only:
Node 12+ is needed to use it and it must be import
ed instead of require
d.
npm:
npm install unified-lint-rule
import {lintRule} from 'unified-lint-rule'
const remarkLintFileExtension = lintRule(
'remark-lint:file-extension',
(tree, file, option = 'md') => {
var ext = file.extname
if (ext && ext.slice(1) !== option) {
file.message('Incorrect extension: use `' + option + '`')
}
}
)
export default remarkLintFileExtension
See contributing.md
in remarkjs/.github
for ways
to get started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
FAQs
unified plugin to make it a bit easier to create linting rules
The npm package unified-lint-rule receives a total of 288,512 weekly downloads. As such, unified-lint-rule popularity was classified as popular.
We found that unified-lint-rule demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.