{"_id":"@cadencejs/eslint-plugin","name":"@cadencejs/eslint-plugin","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@cadencejs/eslint-plugin","version":"0.1.0","description":"An experimental, **brutally strict** ESLint config for **forcing** clean, less-buggy TypeScript code.","keywords":["eslint","eslintplugin","eslint-plugin","cadence"],"author":{"name":"zkldi"},"main":"lib/index.js","dependencies":{"eslint-config-prettier":"8.5.0","eslint-plugin-eslint-plugin":"4.1.0","eslint-plugin-import":"2.26.0","eslint-plugin-node":"11.1.0","eslint-plugin-prettier":"4.0.0","@typescript-eslint/eslint-plugin":"5.22.0","@typescript-eslint/parser":"5.22.0","prettier":"2.6.2"},"devDependencies":{"@types/eslint":"^8.4.2","@types/tap":"^15.0.7","tap":"^16.2.0","eslint":"8.14.0","ts-node":"^10.7.0","typescript":"4.6.4"},"engines":{"node":"12.x || 14.x || >= 16"},"peerDependencies":{"eslint":">=8"},"license":"ISC","scripts":{"build":"tsc","lint":"eslint .","test":"tap","snap":"tap","prepublish":"tsc"},"types":"./lib/index.d.ts","_id":"@cadencejs/eslint-plugin@0.1.0","_integrity":"sha512-ng0mHM7+kX9kPK17l80EgXt1/GT1Fvm2bl2L4MCAEdplqG/b6SXIFwmTT2tJXd8GcoVOI2EjNtox0hL0hBUbJg==","_resolved":"/tmp/a3da625abcb12d9c9bf6f1472477e5cc/cadencejs-eslint-plugin-0.1.0.tgz","_from":"file:cadencejs-eslint-plugin-0.1.0.tgz","_nodeVersion":"16.15.1","_npmVersion":"8.11.0","dist":{"integrity":"sha512-ng0mHM7+kX9kPK17l80EgXt1/GT1Fvm2bl2L4MCAEdplqG/b6SXIFwmTT2tJXd8GcoVOI2EjNtox0hL0hBUbJg==","shasum":"57911f6d9fa4186d05e0567ab02e19b6cd0a9f13","tarball":"https://registry.npmjs.org/@cadencejs/eslint-plugin/-/eslint-plugin-0.1.0.tgz","fileCount":26,"unpackedSize":200159,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDkDz1Pf3KFklKd850Ku8EC9Wsqf3YRPlY5Z5brT5V7QAiAnhQY06TaCnhYjn3FeB3HW4p8gzI1yke9/GBvEFXYtBw=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiw3fKACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq8ww//TxoVEqwiDlZo9iCJRS3luRFLstXQOYYClHvKQ7iccuJodM14\r\n9puQDlCZQev5cPnFxIwnIGOquFgS0PlmMFvizdacVsTj1M0IELI+gn/yXBBQ\r\nkC2xpvsvlq6KBo1TKAtywxiWWRPvHliNKbJCh6fHMWQIpbUbUJN1V5G4wnoG\r\ntGgVmlV8meQvbwpgLDCRm7Aa42bEeyfzE6VPPOTjmF4sH1vFyY4wiNxwZ2hb\r\nmKRa1Mqz6WVMD3rpM4L+x7D7KVUOl6+LYs1Lug9/SkTpfzu++AbvzGRT2Sy1\r\nbtixsj1La/cd5755aE6++LWsAQhQfz/Wbz94Tnnd00UdYUCEWMjAQE0IgK1h\r\njSObj/EdkL302DwdaZt3EiAMXU5C3463mZw90DPV2jH6GzT6lFUrF15C0sVt\r\nyiQBRTrog3kJiemopYm1mLiCZ2yhYOJLS8jS/95y57KXCBfdSQREQB7nGmK+\r\n3N2UWRuoZzk9v03pbh0NE/8v42BuQlpVHLZmw4FEpMVt2zG4EupPO+nAmpb6\r\n7q4LtKwItLoUfIqIifPvTbwGy6j7/f/rOTlh8mX9i2zLchBIAJNW3gMgLQLm\r\nrL/NFK84tLIpXothPkicpv3zaf8nkanH/EXdjYd3Z9pGdfqeWKZP2QzePLNT\r\ncLgruMt/Q+WqTCpE9LtZ3lGidBDXK7Ztvio=\r\n=NMu+\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"zkldi","email":"ddhitone@gmail.com"},"directories":{},"maintainers":[{"name":"zkldi","email":"ddhitone@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/eslint-plugin_0.1.0_1656977353799_0.8831499940921801"},"_hasShrinkwrap":false}},"time":{"created":"2022-07-04T23:29:13.735Z","0.1.0":"2022-07-04T23:29:14.041Z","modified":"2022-07-04T23:29:14.188Z"},"maintainers":[{"name":"zkldi","email":"ddhitone@gmail.com"}],"description":"An experimental, **brutally strict** ESLint config for **forcing** clean, less-buggy TypeScript code.","keywords":["eslint","eslintplugin","eslint-plugin","cadence"],"author":{"name":"zkldi"},"license":"ISC","readme":"# Cadence (Alpha)\n\nCadence is an experimental, **brutally strict** ESLint config for **forcing** clean, less-buggy TypeScript code.\n\n**NOTE: Cadence is an experimental config, and in its very early phases. I can be swayed on some rules. Make a discussion or an issue on this repo and I'll get to it!**\n\n**NOTE: Cadence is a preset compiling mostly other peoples hard work. If you like this, you should support upstream.**\n\n- [ESLint](https://github.com/ESLint)\n- [typescript-eslint](https://github.com/typescript-eslint)\n- [eslint-plugin-import](https://github.com/import-js/eslint-plugin-import)\n- [prettier](https://github.com/prettier/prettier)\n\n## Try it out on your own code!\n\nThe [Cadence Playground](https://cadence.zkldi.xyz/playground) will automatically show how Cadence treats your code.\n\n## What's the point?\n\n- It's brutally strict. (The config is nearly one thousand lines long.)\n\nNow, let's be honest. TypeScript has a *lot* of warts and footguns. TS would arguably be a better language if we could just cut off the bad parts. So let's do it!\nCadence is strict to the point where these footguns are caught for you *at lint time*. No longer do you have to fall for subtle JS-isms like these:\n```js\nisNaN(\"foo\"); // true\nNumber.isNaN(\"foo\"); // false\n```\n```js\nfunction doStuff() {\n    switch (foo) {\n        case \"bar\":\n            let thing = 5;\n            return thing;\n        case \"baz\":\n            let thing = 6; // SyntaxError, thing is already defined !!!\n            return thing;\n    }\n}\n```\n```js\nconst users = [\"joey\", \"tim\", \"bob\"];\n\n// This actually happens in parallel !!\nusers.forEach(async user => {\n    console.log(`Fetching ${user}'s email...`);\n    const usersEmail = await fetch(`https://example.com/api/user-email?user=${user}`).then(r => r.text());\n\n    console.log(`Got ${usersEmail}!`)\n})\n\nconsole.log(`Done!`);\n\n// Will output something like:\n// Done!\n// -- the order of everything below this point is non-determinis tic!\n// Fetching joey's email...\n// Fetching tim's email...\n// Fetching bob's email...\n// Got joey.dev@gmail.com!\n// Got tim@example.com!\n// Got bob@example.com!\n```\n\nWhen developing Cadence, I was honestly unconvinced of its merit. However, after it found **14** bugs (some of which were serious!) in one of my codebases (~50kloc), I was completely sold.\n\n- All code linted and formatted with the Cadence config **must have** the same format and rhythm to it. (get it?)\n\nYou even get cleaner git diffs for free.\nYour imports? Those are automatically put in the right place by the linter.\nTypescript union order? Deterministic.\n\n- Cadence code is *forced* to be easily legible.\n\nCadence **enforces** whitespace, padding and other pretty-isms around the codebase to split up logic visually.\n\nYou might think this is nitpicky, but since it can be enforce automatically, all code with Cadence is guaranteed not to be a clumped mess of logic.\n\nIt is **extremely difficult** to write messy code with Cadence enabled!\n\nLogic should be separated, and sparse!\nWe shouldn't have to think about anything other than business logic while reading code.\n\n```js\nfunction scrimbly() {\n    const foo = \"asdf\";\n    const bar = 123;\n    let {more, variables} = scrobbly(bar);\n    // subFunction foos the bar and scrimbles the bimble\n    function subFunction() {\n        return 1;\n    }\n    if (statement) { \n        doThing();\n    }\n    return foo;\n}\n```\nWill be **forcibly** changed to:\n```js\nfunction scrimbly() {\n    const foo = \"asdf\";\n    const bar = 123;\n    const { more, variables } = scrobbly(bar);\n\n    // subFunction foos the bar and scrimbles the bimble\n    function subFunction() {\n        return 1;\n    }\n\n    if (statement) {\n        doThing();\n    }\n\n    return foo;\n}\n```\n\n## Using Cadence properly\n\nA lot of Cadence's linting/formatting opinions will be **automatically** fixed.\nIt would be a very frustrating experience to have to go through the codebase and apply Cadence's changes by hand!\n\nSimilarly, Cadence is intended to be a real-time feedback loop on your codebase.\nAs such, it's intended to be used by running *on save* in your editor of choice.\nFor VSCode, this just means setting ESLint as your default formatter.\n\n## Tools are here to help you!\n\nCadence might be frustrating at times, the same way something like TypeScript's type checking is.\nAt its core though, Cadence and TS are trying to do the exact same thing - Stop you from making mistakes! It might be frustrating to work around hoops when you *think you know* your code is safe, but when it actually saves your bacon, it's all worth it.\n\nSometimes, however, Cadence might just be straight up incorrect about parts of your code.\nTo get around this, use the standard ESLint ignore syntax.\n```js\n// eslint-disable-next-line rule-thats-giving-you-trouble\n```\n\nIf you're doing something across your codebase that Cadence is giving you trouble about, you might want to reduce it to a warning in your `.eslintrc`.\n```json\n{\n    \"plugins\": [\n        \"cadence\"\n    ],\n    \"extends\": [\n        \"plugin:cadence/recommended\"\n    ],\n    \t\"rules\": {\n\t\t\"@typescript-eslint/no-unsafe-assignment\": \"warn\"\n\t},\n}\n```\n\n\n**Don't set rules to \"off\" unless you know EXACTLY what you're doing.**\nLeaving would-be errors as warnings is useful for other developers -- they'll know something is out-of-the-ordinary here!\n\n## What's the point of rule (xyz)?\n\nAt the moment, you'll have to check `src/configs/recommended.ts` in this repository to see my stance on each rule.\nIn the future, I hope to have documentation for why every single rule is enabled.\nThis would double up as a very useful resource on JS/TS footguns!\n\nIf the explanation in there doesn't satisfy, feel free to open a [Discussion](https://github.com/CadenceJS/Cadence).\n\n\n## Setup (Fresh Repository)\n\nYou'll first need to install [ESLint](https://eslint.org/) and this plugin:\n\n```sh\n# Use your preferred package manager. If you don't have strong opinions on this, here's mine.\n# I would **highly** recommend pnpm, as its the most sensible.\npnpm add eslint -D\n\n# Yarn is also pretty good, but there's a couple of pain points and generally\n# worse performance.\nyarn add eslint -D\n\n# use NPM if you have to. It's slow, riddled with design flaws, and generally a pain\n# in the ass.\nnpm i eslint @cadence/ --save-dev\n```\n\nNext, install `eslint-plugin-cadence`:\n\n```sh\nnpm install  --save-dev\n\n# or\nyarn add eslint-plugin-cadence -D\n\n# or\npnpm add eslint-plugin-cadence -D\n```\n\n## Usage\n\nCreate an `.eslintrc` file next to your `package.json`. Fill it with the following content.\n\n```json\n{\n    \"plugins\": [\n        \"cadence\"\n    ],\n    \"extends\": [\n        \"plugin:cadence/recommended\"\n    ],\n}\n```\n\nYou might want to also make an `.eslintignore` file:\n```sh\n# We don't want to lint node_modules! \nnode_modules\n```\n\n## Migrating to Cadence\n\nMigrating a codebase to Cadence is honestly a pain in the ass.\nAlthough it can automatically fix a hell of a lot of the issues in your codebase,\nyou will almost certainly have to do some manual work.\n\nThis is especially true if you depend on unsafe/unclean things throughout your codebase, such as\na liberal use of `any`, `for (const k in obj)`, `[].forEach()`, etc.\n\nIn my opinion, the best way to migrate to Cadence is as follows:\n\n1. Make a new git branch off of your main branch.\n2. Install Cadence there, and run `eslint . --fix --ext .ts`\n3. It'll likely give you some errors and warnings. Step through them all and start analysing them.\n4. It's quite likely it'll find some bugs in your codebase, aswell! That should hopefully convince you it's worth the setup effort.\n5. If you don't like it though, you can always just straight up discard the branch and go back to normal.\n6. Once you've analysed and fixed all of the errors and warnings, merge it back into your main branch!","readmeFilename":""}