{"_id":"@crabnebula/eslint-protection","name":"@crabnebula/eslint-protection","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@crabnebula/eslint-protection","version":"0.0.1","type":"module","description":"eslint rule to protect parts of the code from unconscious change","main":"eslint-protection.js","scripts":{"lint":"eslint ./example1.js","test":"node protection.test.js"},"keywords":[],"author":{"name":"Alex Lohr","email":"alex@crabnebula.dev"},"license":"(MIT OR Apache-2.0)","devDependencies":{"eslint":"^9.28.0"},"_id":"@crabnebula/eslint-protection@0.0.1","gitHead":"843ae7c17c554aff3a1ef2c16873df5d0be1be36","_nodeVersion":"20.19.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-xX6LMuD3jK2SATcNnBsqEWmFaJt6fVqBPQSUD92Jdl0XCp2o8dqQ0YzzRn9xqYNCkNZsELrG4NZuL6y508FGOg==","shasum":"b254a89da4bf75d6bb4fc0b183924789599f8a1f","tarball":"https://registry.npmjs.org/@crabnebula/eslint-protection/-/eslint-protection-0.0.1.tgz","fileCount":10,"unpackedSize":21446,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDMcUev9SESSFNtBl3us0SIZBjgGZ6rz08swFB12KwFuQIhAIFWMVrf7fJ4r1FLH5ECKLxCRbWOyqSpdDuz6ezapR4u"}]},"_npmUser":{"name":"crabnebula-npm","email":"npm-admin@crabnebula.dev","actor":{"name":"crabnebula-npm","email":"npm-admin@crabnebula.dev","type":"user"}},"directories":{},"maintainers":[{"name":"crabnebula-npm","email":"npm-admin@crabnebula.dev"},{"name":"lucasfernog-crabnebula","email":"lucas@crabnebula.dev"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/eslint-protection_0.0.1_1750938751968_0.609735948317589"},"_hasShrinkwrap":false}},"time":{"created":"2025-06-26T11:52:31.863Z","0.0.1":"2025-06-26T11:52:32.137Z","modified":"2025-06-26T11:52:32.423Z"},"maintainers":[{"name":"crabnebula-npm","email":"npm-admin@crabnebula.dev"},{"name":"lucasfernog-crabnebula","email":"lucas@crabnebula.dev"}],"description":"eslint rule to protect parts of the code from unconscious change","keywords":[],"author":{"name":"Alex Lohr","email":"alex@crabnebula.dev"},"license":"(MIT OR Apache-2.0)","readme":"# @crabnebula/eslint-protected\n\nA small lint rule to protect parts of the code from unconscious change. It uses a comment containing the `//@protected` keyword, an optional number of lines or `*` for the whole file, and a hash that is calculated from the code meant to be protected.\n\nCode that differs from the saved hash will be reported.\n\n## Installation and Configuration\n\nDepending on your preferred package manager, run\n\n```sh\nnpm add --save-dev @crabnebula/eslint-protected\n// or\nyarn add -D @crabnebula/eslint-protected\n// or\npnpm add -D @crabnebula/eslint-protected\n```\n\nThen in your eslint config, add\n\n```js\nimport { defineConfig } from \"eslint/config\";\nimport protection from \"@crabnebula/eslint-protection\";\n\nexport default defineConfig({    \n    plugins: { protection },\n    rules: {\n        \"protection/protect\": \"error\"\n    }\n});\n```\n\nIdeally, you set up `eslint` as a guarding mechanism for commits using e.g. `husky`; first, install the required dependencies:\n\n```sh\nnpm add --save-dev husky lint-staged @crabnebula/husky-protection\n# or\nyarn add -D husky lint-staged @crabnebula/husky-protection\n# or\npnpm add -D husky lint-staged @crabnebula/husky-protection\n```\n\nNext, initialize Husky:\n\n```sh\nnpx husky-init && npm install\n# or\nnpx husky-init && yarn\n# or\npnpx husky-init && pnpm i\n```\n\nLastly, add a pre-commit hook:\n\n```sh\nnpx husky add .husky/pre-commit \"npx lint-staged\"\nnpx husky add .husky/pre-commit \"node_modules/@crabnebula/husky-protection/index.js\"\n# or\npnpx husky add .husky/pre-commit \"npx lint-staged\"\npnpx husky add .husky/pre-commit \"node_modules/@crabnebula/husky-protection/index.js\"\n\n# in either case, make it executable:\nchmod +x .husky/pre-commit .husky/_/husky.sh\n```\n\nThis will add the linter and another protection commit hook that will block commits that remove more protection comments than they add.\n\n## Usage\n\nTo get the hash, just add `//@protected` without a hash and look at the error message.\n\n### Protecting a file\n\n```js\n//@protected * [hash]\n```\n\n### Protecting a single line\n\n```js\n//@protected [hash]\n```\n\n### Protecting multiple lines\n\n```js\n//@protected 2 [hash]\n```\n\nWhere `2` is the number of lines that should be protected below the comment.\n\n## VS Code extension\n\nThere is a VS Code extension [`vscode-eslint-protected`](https://github.com/crabnebula-dev/vscode-eslint-protected) that will add the comments for you automatically.\n","readmeFilename":"README.md","_rev":"1-e71730e2927d1debe0d742248ffbf157"}