npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

libdenolint

v2.0.14

Published

Deno lint library binding for Node.js

Downloads

31

Readme

libdenolint

Latest version Dependency status

Deno lint library binding for Node.js

Used in bundler plugins: rollup-plugin-denolint for Rollup, esbuild-plugin-denolint for esbuild, webpack-loader-denolint for Webpack.

This project started as fork of customised @node-rs/deno-lint, adding the flexibility of eslint:

  • Scan specific directories with specific ignore patterns (631, 647)
  • Scan directories configured by files.include (635, 645)
  • Fix handling of the configuration files.exclude (635, 646)
  • Support disabling rules in souces using eslint-disable (630, 642)
  • Support including and excluding rules in the lint method (631, 643)
  • Offer both synchronous and asynchronous methods (650)
  • Allow specifying directories, files and patterns as input for checking
  • Print warning messages in pretty or compact formats

Synopsis

Scan sources in the current directory:

import { denolint } from 'libdenolint'

process.exitCode = await denolint() ? 0 : 1

Check one source file:

import { readFile } from 'fs/promises'
import { lint } from 'libdenolint'

const filepath = 'src/index.js'
const source = await readFile(filepath)

try {
  const warnings = await lint(filepath, source)
  for (const warning of warnings) console.warn(warning)
} catch ({ message }) {
  console.error(message)
}

Usage of denolint

import { denolint, denolintSync } from 'libdenolint'

interface DenoLintOptions {
  scanDirs?: string[],
  ignorePatterns?: string[]
}

function denolint(
  projectDir?: string, configPath?: string,
  options?: DenoLintOptions, signal?: AbortSignal
): Promise<boolean>

function denolintSync(
  projectDir?: string, configPath?: string, options?: DenoLintOptions
): boolean

The project directory will be scanned if no directory is specified either on the command line or in the config file. Directories from scanDirs take precedence over the directories in the config file.

Returns true if all files are valid, otherwise false.

projectDir

  • Type: String
  • Default: current directory

Root directory of the project, which contains files .denolintignore or .eslintignore. Defaults to the current directory.

configPath

  • Type: String
  • Default: '.denolint.json'

Config path relative to the lint path. If not provided, a .denolint.json in the project directory will be tried to load. If an empty string is specified explicitly, it will disable searching for the default config file.

Config file must be a JSON file:

Example:

{
  "files": {
    "include": ["src", "test"],
    "exclude": ["examples"]
  },
  "rules": {
    "tags": ["recommended"],
    "exclude": [
      "no-explicit-any",
      "ban-unknown-rule-code",
      "no-window-prefix",
      "no-empty-interface",
      "ban-types",
      "ban-untagged-todo",
      "no-unused-vars",
      "ban-ts-comment",
      "no-case-declarations",
      "no-this-alias"
    ]
  }
}

Check out deno_lint rules for all rules.

scanDirs

  • Type: String[]
  • Default: []

Directories to scan for sources. The project directory will be scanned if none specified.

ignorePatterns

  • Type: String[]
  • Default: []

File patterns to ignore when the source directories are scanned. I applies only to directories specified on the command line; not to the directories specified by files.include from the config file.

dryRun

  • Type: Boolean
  • Default: false

Only lists the files names, which would be processed, without checking their syntax. It can be used to learn what files will be processed.

signal

  • Type: AbortSignal
  • Default: undefined

A signal from an AbortController to abort the operation. Optional.

Usage of lint

import { lint, lintSync } from 'libdenolint'

function lint(
  fileName: string, sourceCode: string | Buffer,
  allRules?: boolean, excludeRules?: string[], includeRules?: string[],
  signal?: AbortSignal
): Promise<Array<string>>

function lintSync(
  fileName: string, sourceCode: string | Buffer,
  allRules?: boolean, excludeRules?: string[], includeRules?: string[]
): Array<string>

Returns an empty array if the files is valid, otherwise the array will contain printable warnings about the problems found. May throw an error in case of a fatal parser failure.

fileName

  • Type: String

The name of the source file for diagnostic messages.

sourceCode

  • Type: String | Buffer

The contents of the source file to be checked.

allRules

  • Type: Boolean
  • Default: false

Whether to enable all rules. If false, denolint will enable only the recommend rules.

excludeRules

  • Type: String[]
  • Default: []

Rules to exclude from all or recommended ones chosen by enableAllRules.

includeRules

  • Type: String[]
  • Default: []

Rules to include in addition to the recommended ones chosen by enableAllRules set to false.

signal

  • Type: AbortSignal
  • Default: undefined

A signal from an AbortController to abort the operation. Optional.

Migration from @node-rs/deno-lint

Methods denolint and lint are synchronous. If you want to retain the synchronous behaviour, call the methods with the Sync suffix:

- denolint(process.cwd(), '.denolint.json')
+ denolintSync(process.cwd(), '.denolint.json')

- lint(fileName, fileContents)
+ lintSync(fileName, fileContents)

Methods denolint and denolintSync return boolean (or a Promise to a boolean) with the result of the syntax check. The value true means success, the value false means a failure. Pay attention, the boolean retuurned by the method denolint from @node-rs/deno-lint has the meaning the other way round!

Troubleshooting

If the installation fails, set the environment variable LIBDENOLINT_DEBUG to true and watch the debugging output on the console.

Support matrix

| Platform | node14 | node16 | node18 | | ---------------- | ------ | ------ | ------ | | Windows x64 | ✓ | ✓ | ✓ | | Windows x32 | ✓ | ✓ | ✓ | | Windows arm64 | ✓ | ✓ | ✓ | | MacOS x64 | ✓ | ✓ | ✓ | | MacOS arm64 | ✓ | ✓ | ✓ | | Linux x64 gnu | ✓ | ✓ | ✓ | | Linux x64 musl | ✓ | ✓ | ✓ | | Linux arm gnu | ✓ | ✓ | ✓ | | Linux arm64 gnu | ✓ | ✓ | ✓ | | Linux arm64 musl | × | × | × | | Android arm64 | × | × | × | | Android armv7 | × | × | × | | FreeBSD x64 | ✓ | ✓ | ✓ |

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

License

Copyright (c) 2020-2022 LongYinan Copyright (c) 2023 Ferdinand Prantl

Licensed under the MIT license.