Lint Fn
raw JSON → 2.45.0 verified Fri May 01 auth: no javascript
lint-fn is a Node.js library (v2.45.0) that runs ESLint with automatic fixes using predefined rules based on file path. It supports JavaScript and TypeScript files, has a peer dependency on TypeScript 4.7.4, and requires Node.js >15. Differentiators include file-path-based rule selection and environment variable support for skipping specific ESLint rules. The package ships TypeScript types, but has a known issue with linting certain TypeScript declaration files like rambda/files/index.d.ts. Development appears slow, with a TODO item referencing lack of ESLint debug config. The library is published on npm and hosted on GitHub under selfrefactor/services.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/lint-fn/index.js from /path/to/your-file.js not supported. ↓
cause Using CommonJS require() to import an ESM-only module with Node.js <15 or without module type.
fix
Use dynamic import: import('lint-fn') or switch to ES modules.
error TypeError: lintFn is not a function ↓
cause Attempting default import without default export, or mixing named and default imports incorrectly.
fix
Use import lintFn from 'lint-fn' for default, or import { lintFn } for named.
error Cannot find module 'typescript' or its corresponding type declarations. ↓
cause TypeScript peer dependency not installed.
fix
npm install typescript@4.7.4 --save-dev
Warnings
breaking Version 2.0+ is ESM-only and requires Node.js >15. CommonJS require() will fail. ↓
fix Use import syntax or upgrade to Node.js >15 and set 'type': 'module' in package.json.
deprecated Default import may be removed in future versions; prefer named import { lintFn } for clarity. ↓
fix Switch to import { lintFn } from 'lint-fn'.
gotcha Linting of TypeScript declaration files (*.d.ts) may not work correctly; manual ESLint debug config needed. ↓
fix Add ESLint debug configuration or avoid linting .d.ts files directly.
gotcha Predefined rules depend on file path; custom rules may be overridden if not passed correctly. ↓
fix Ensure custom rules are passed in the options object; check documentation for path-based rule precedence.
Install
npm install lint-fn yarn add lint-fn pnpm add lint-fn Imports
- default wrong
const lintFn = require('lint-fn')correctimport lintFn from 'lint-fn' - lintFn
import { lintFn } from 'lint-fn' - type LintOptions wrong
import { LintOptions } from 'lint-fn'correctimport type { LintOptions } from 'lint-fn'
Quickstart
import lintFn from 'lint-fn';
const filePath = 'src/index.ts';
const options = {
fix: true,
rules: {
'no-unused-vars': 'error'
},
// SKIP_ESLINT_RULES env var can skip rules: 'no-nested-ternary, max-len'
};
process.env.SKIP_ESLINT_RULES = 'no-nested-ternary';
lintFn(filePath, options)
.then((result) => {
console.log('Lint fixed:', result);
})
.catch((error) => {
console.error('Lint error:', error);
});