{"id":13238,"library":"gitlint-parser-base","title":"Gitlint Parser Base","description":"gitlint-parser-base is a foundational utility package providing the core parsing logic for the `gitlint` ecosystem. As of version 2.0.0, it exports a `Parser` class and a `createContext` function, enabling structured extraction of header, body, and footer components from raw Git commit messages. This package primarily serves as an internal dependency for the main `gitlint` project and other related tools that require a standardized way to interpret commit message structure. Its release cadence is closely tied to the `gitlint` project's evolution, with updates driven by changes in Git message parsing requirements or internal architectural enhancements. It is designed to be a building block for linting and analysis, rather than a standalone, general-purpose text parser, specializing in the nuances of Git commit conventions.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/evanlucas/gitlint-parser-base","tags":["javascript"],"install":[{"cmd":"npm install gitlint-parser-base","lang":"bash","label":"npm"},{"cmd":"yarn add gitlint-parser-base","lang":"bash","label":"yarn"},{"cmd":"pnpm add gitlint-parser-base","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is a CommonJS module. Direct ESM `import` is not supported without a transpiler or dynamic `import()`.","wrong":"import { Parser } from 'gitlint-parser-base';","symbol":"Parser","correct":"const { Parser } = require('gitlint-parser-base');"},{"note":"Used internally by the `Parser` class, but can be accessed directly for custom context handling or testing. It is a CommonJS export.","wrong":"import { createContext } from 'gitlint-parser-base';","symbol":"createContext","correct":"const { createContext } = require('gitlint-parser-base');"}],"quickstart":{"code":"const { Parser } = require('gitlint-parser-base');\n\nconst commitMessage = `feat(parser): add base parser for gitlint\\n\\nThis commit introduces the foundational parser for gitlint.\\nIt extracts header, body, and footer from a commit message.\\n\\nFixes #123\\nRefs #456`;\n\ntry {\n  const parser = new Parser(commitMessage);\n  const parsed = parser.parse();\n\n  console.log('Header:', parsed.header);\n  console.log('Body:', parsed.body);\n  console.log('Footer:', parsed.footer);\n\n  // Example of accessing parsed header properties (assuming parseHeader populates them)\n  if (parsed.header && typeof parsed.header === 'object') {\n    console.log('Header type (scope):', parsed.header.type, parsed.header.scope);\n  }\n\n} catch (error) {\n  console.error('Error parsing commit message:', error.message);\n}","lang":"javascript","description":"Demonstrates how to import the `Parser` class, instantiate it with a commit message, and then parse the message to access its structural components like header, body, and footer."},"warnings":[{"fix":"Use CommonJS `require` syntax: `const { Parser } = require('gitlint-parser-base');` or use dynamic `import()` if truly in an ESM context: `const { Parser } = await import('gitlint-parser-base');`.","message":"The `gitlint-parser-base` package is distributed as a CommonJS module. Attempting to use `import { Parser } from 'gitlint-parser-base';` in an ESM context will result in a syntax error or runtime error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Review your code for reliance on undocumented internals. Upgrade carefully and test thoroughly, ensuring only the documented `Parser` class and `createContext` function are utilized.","message":"Version 2.0.0 introduced significant internal changes to how parsing is handled, potentially affecting consumers who were relying on internal or undocumented APIs from version 1.x. The public API surface (Parser class, createContext) has been stabilized, but direct access to internal modules or properties may behave differently.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always provide a valid string representing a Git commit message to the `Parser` constructor. Implement input validation before instantiation to handle edge cases gracefully.","message":"The `Parser` class requires a raw commit message string in its constructor. Passing malformed input or non-string values may lead to unexpected parsing results or errors, as it expects a specific Git commit message format.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If full linting capabilities are required, use the main `gitlint` package. This package is suitable for scenarios where only structural decomposition of commit messages is needed.","message":"This package is primarily intended as a base utility for `gitlint`. While usable independently, it does not include any linting rules or validation logic itself. It only provides the structural parsing.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change the import statement to CommonJS `require`: `const { Parser } = require('gitlint-parser-base');`.","cause":"Attempting to use ESM `import { Parser } from 'gitlint-parser-base';` with a CommonJS-only package.","error":"SyntaxError: Named export 'Parser' not found. The requested module 'gitlint-parser-base' does not provide an export named 'Parser'"},{"fix":"Ensure you are destructuring the `Parser` class correctly from the CommonJS `module.exports`: `const { Parser } = require('gitlint-parser-base');`","cause":"Attempting to call `new Parser()` after incorrect import (e.g., `const Parser = require('gitlint-parser-base').Parser;` or an invalid default import).","error":"TypeError: Parser is not a constructor"},{"fix":"Always provide a non-empty string as the `commitMessage` argument to `new Parser(commitMessage)`. Validate the input before creating a parser instance.","cause":"This error can occur if the commit message provided to the `Parser` constructor is `null`, `undefined`, or an empty string, leading to subsequent internal operations failing to access properties on the expected message content.","error":"TypeError: Cannot read properties of undefined (reading 'type') at Parser.parse (index.js:XX:YY)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}