{"id":30622261,"url":"https://github.com/assignuser/ast-grep-cmake-precommit","last_synced_at":"2025-08-30T15:36:02.178Z","repository":{"id":305526294,"uuid":"1020376709","full_name":"assignUser/ast-grep-cmake-precommit","owner":"assignUser","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-21T00:06:20.000Z","size":121,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-21T00:44:18.882Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/assignUser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-15T19:15:07.000Z","updated_at":"2025-07-21T00:05:38.000Z","dependencies_parsed_at":"2025-07-21T00:44:19.352Z","dependency_job_id":null,"html_url":"https://github.com/assignUser/ast-grep-cmake-precommit","commit_stats":null,"previous_names":["assignuser/cmake-linter","assignuser/ast-grep-cmake-precommit"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/assignUser/ast-grep-cmake-precommit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assignUser%2Fast-grep-cmake-precommit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assignUser%2Fast-grep-cmake-precommit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assignUser%2Fast-grep-cmake-precommit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assignUser%2Fast-grep-cmake-precommit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/assignUser","download_url":"https://codeload.github.com/assignUser/ast-grep-cmake-precommit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assignUser%2Fast-grep-cmake-precommit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272871255,"owners_count":25007133,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-30T15:35:57.092Z","updated_at":"2025-08-30T15:36:02.171Z","avatar_url":"https://github.com/assignUser.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CMake Integration for ast-grep\n\nThis project adds CMake support to [ast-grep](https://ast-grep.github.io/), letting you craft custom linting rules for your CMake projects.\n\n## Features\n\n- **Custom CMake Language Support**: Uses the well maintained [tree-sitter-cmake](https://github.com/uyha/tree-sitter-cmake) parser to allow ast-grep to understand CMake syntax\n- **Flexible Rule System**: Bring your own rules - define linting rules using ast-grep's powerful pattern matching\n- **Pre-commit Hook**: The hook uses `language: node`, providing maximum portability between OSes\n- **Example Rules**: Includes reference rules demonstrating common CMake linting patterns\n\n## Using as a Pre-commit Hook\n\nTo use this CMake integration in your project as a pre-commit hook, you need to provide your own rules:\n\n1. Create a directory for your CMake rules in your project (e.g., `cmake-rules/`):\n   ```yaml\n   # Example rule: cmake-rules/my-cmake-rule.yml\n   id: my-cmake-rule\n   message: Custom CMake rule message\n   severity: warning\n   language: cmake\n   rule:\n     pattern: some_cmake_command($$$)\n   ```\n\n2. Add to your `.pre-commit-config.yaml`:\n   ```yaml\n   repos:\n     - repo: https://github.com/assignUser/ast-grep-cmake-precommit\n       rev: \u003cref\u003e  # Use a specific tag/commit, not 'main'\n       hooks:\n         - id: cmake-lint\n           args: [--rule-dirs, ./cmake-rules, --]\n   ```\n   When used through pre-commit ast-grep seems to leave behind ANSI Color codes on the command line. The only current fix seems to be to use `--color never` to suppress color completely.\n\n3. Install the hook:\n   ```bash\n   pre-commit install\n   ```\n\n4. Run manually (optional):\n   ```bash\n   pre-commit run cmake-lint --all-files\n   ```\n\n### Advanced Usage\n\nYou can specify multiple rule directories and utility directories:\n\n```yaml\nrepos:\n  - repo: https://github.com/assignUser/ast-grep-cmake-precommit\n    rev: \u003cref\u003e\n    hooks:\n      - id: cmake-lint\n        args: [--rule-dirs, ./cmake-rules, ./shared-rules, --util-dirs, ./cmake-utils, --, --color never]\n```\n\n\u003e [!IMPORTANT]  \n\u003e The `--` separator at the end of the args-list is required. It marks the boundary between hook-specific arguments and ast-grep arguments, ensuring proper argument parsing. Always include `--` after your last directory argument, before any ast-grep arguments or as the last element, if you don't pass any direct arguments.\n\n### Local Development of the hook\n\nFor local development of the hook use `pre-commit try-repo path/to/repo cmake-lint` to confirm that the hook works as expected.\nYou will need to add your args to `.pre-commit-hooks.yaml`, as `try-repo` does not support custom arguments.\n\n\n## Writing Your Own Rules\n\nCreate rules in your project's rule directory. Example rule:\n\n```yaml\nid: cmake-minimum-version\nmessage: CMake minimum version should be specified\nseverity: warning\nlanguage: cmake\nrule:\n  pattern: cmake_minimum_required($$$)\n```\n\nFor rule writing guidance, see the [ast-grep rule documentation](https://ast-grep.github.io/reference/yaml.html).\n\n### Example Rules\n\nThis repository includes example rules in the `rules/` directory that demonstrate common CMake linting patterns:\n\n- `cmake-minimum-version-*.yml` - Check CMake minimum version requirements\n- `deprecated-commands.yml` - Detect usage of deprecated CMake commands\n- `avoid-directory-wide-functions.yml` - Prefer target-specific functions\n- `no-hardcoded-absolute-paths.yml` - Avoid hard-coded absolute paths\n- `prefer-find-package.yml` - Prefer find_package over manual library finding\n\nThese can serve as a starting point for your own rules.\n\n### File Support\n\nThe linter recognizes these file patterns:\n- `*.cmake`\n- `**/CMakeLists.txt`\n\n`*.cmake.in` is not supported as it's not valid CMake that ast-grep can parse.\n\n### Testing Your Rules\n\nYou can test your rules using ast-grep's test functionality:\n\n1. Create test files in a `rules-test/` directory alongside your rules\n2. Run `ast-grep test` to validate your rules against test cases\n\nSee the [ast-grep test documentation](https://ast-grep.github.io/guide/test-rule.html) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fassignuser%2Fast-grep-cmake-precommit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fassignuser%2Fast-grep-cmake-precommit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fassignuser%2Fast-grep-cmake-precommit/lists"}