{"id":17076,"library":"yaml-lint","title":"YAML Linter CLI and API","description":"yaml-lint is a straightforward command-line interface (CLI) tool and programmatic API for validating YAML files against a specified schema or for general syntax correctness. It's currently stable at version 1.7.0. The package has seen consistent maintenance releases, with the latest significant update fixing glob pattern issues on Windows and migrating to TypeScript in version 1.3.0. Its key differentiators include the ability to specify different YAML schemas (DEFAULT, FAILSAFE, JSON, CORE), flexible configuration via JSON files, environment variables, or CLI arguments, and support for ignoring files using glob patterns. It processes multi-document YAML sources and provides clear error reporting for invalid files.","status":"active","version":"1.7.0","language":"javascript","source_language":"en","source_url":"git://github.com/rasshofer/yaml-lint","tags":["javascript","yaml","lint","linter","cli","typescript"],"install":[{"cmd":"npm install yaml-lint","lang":"bash","label":"npm"},{"cmd":"yarn add yaml-lint","lang":"bash","label":"yarn"},{"cmd":"pnpm add yaml-lint","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"While CommonJS `require` still works for the main export, `yaml-lint` migrated to TypeScript and ES2015+ syntax in v1.3.0 and v1.1.0 respectively. For modern Node.js and bundled environments, ESM imports are preferred.","wrong":"const yamlLint = require('yaml-lint');","symbol":"yamlLint","correct":"import yamlLint from 'yaml-lint';"},{"note":"The primary programmatic function is accessed as a method on the default export. There is no direct named export for `lint` itself.","symbol":"lint","correct":"import yamlLint from 'yaml-lint';\nyamlLint.lint('...');"},{"note":"Since v1.3.0, the package ships with TypeScript types. Specific types for options or results can be imported directly.","symbol":"Types","correct":"import type { LintOptions } from 'yaml-lint';"}],"quickstart":{"code":"import yamlLint from 'yaml-lint';\nimport { readFileSync } from 'fs';\nimport { join } from 'path';\n\n// Example 1: Linting a string directly\nyamlLint\n  .lint('key: value\\narray:\\n  - item1\\n  - item2')\n  .then(() => {\n    console.log('String content is valid YAML.');\n  })\n  .catch((error) => {\n    console.error('String content is invalid YAML:', error.message);\n  });\n\n// Example 2: Linting a file (assuming a test.yaml exists for this example)\nconst filePath = join(process.cwd(), 'test.yaml');\n// To make this runnable, create a dummy test.yaml for demonstration:\n// fs.writeFileSync(filePath, 'foo: bar\\nversion: 1.0');\n\n// For a real scenario, ensure 'test.yaml' exists and contains valid YAML\ntry {\n  const fileContent = readFileSync(filePath, 'utf8');\n  yamlLint.lint(fileContent)\n    .then(() => console.log(`${filePath} is valid YAML.`))\n    .catch(error => console.error(`${filePath} is invalid YAML:`, error.message));\n} catch (err) {\n  console.warn(`Could not read ${filePath}. Please create it for file linting demo.`);\n  // Example of how you'd explicitly fail a file lint for a broken file:\n  // yamlLint.lint('invalid: - \\n  - yaml')\n  //   .catch(error => console.error('Intentional invalid file content error:', error.message));\n}","lang":"typescript","description":"Demonstrates both direct string linting and how to lint the content of a file using the programmatic API."},"warnings":[{"fix":"Upgrade your Node.js runtime to version 8 or higher. The current package targets modern Node.js environments.","message":"Node.js 0.x is no longer supported. Users on older Node.js versions must upgrade to at least Node.js 8 or newer.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure all `ignore` glob patterns consistently use forward slashes. This was specifically fixed in v1.7.0 to enforce forward slashes, but user input still needs to adhere to this.","message":"When configuring ignore patterns, always use forward slashes (e.g., `dir/*.yaml`) regardless of the operating system. Backslashes on Windows might lead to patterns not being correctly applied.","severity":"gotcha","affected_versions":">=1.7.0"},{"fix":"Adjust glob patterns to be explicit about case if necessary, as automatic case-insensitivity might not be applied as expected across all platforms.","message":"The `nocase` rule for glob patterns was removed in an earlier version (1.2.3) to prevent issues on Windows. This might affect how case-insensitive file matching works for ignore patterns.","severity":"deprecated","affected_versions":">=1.2.3"},{"fix":"Update to `yaml-lint` version 1.4.0 or newer to ensure all failing files are reported when using the CLI.","message":"By default, the CLI will only display the first failing file it encounters. To see all failing files, ensure you are using a version that supports displaying multiple errors.","severity":"gotcha","affected_versions":"<1.4.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Set `YAMLLINT_SCHEMA` to one of the valid schema types: `DEFAULT_SCHEMA`, `FAILSAFE_SCHEMA`, `JSON_SCHEMA`, or `CORE_SCHEMA`.","cause":"An unsupported or misspelled schema name was provided via the `YAMLLINT_SCHEMA` environment variable.","error":"Error: YAMLLINT_SCHEMA environment variable value is not a valid schema type."},{"fix":"Run `npm install --save-dev yaml-lint` for local project usage or `npm install -g yaml-lint` for global CLI use.","cause":"The `yaml-lint` package is not installed or not accessible in the current project's `node_modules`.","error":"Cannot find module 'yaml-lint'"},{"fix":"Ensure your Node.js environment supports ESM (Node.js 12+ with 'type: module' in package.json, or file extension .mjs). Alternatively, use `import yamlLint from 'yaml-lint';` in an ESM context.","cause":"Attempting to use `require()` on a module that primarily uses ES Modules syntax in an environment that doesn't correctly transpile or resolve ESM.","error":"SyntaxError: Unexpected token 'export'"}],"ecosystem":"npm","meta_description":null}