|
| 1 | +Code Style for `css-blocks` |
| 2 | +=========================== |
| 3 | + |
| 4 | +This project adheres to the following conventions for code and its style. |
| 5 | +These conventions govern the code that runs during build-time. There are |
| 6 | +separate conventions for code intended to run in the browser. |
| 7 | + |
| 8 | +Node Support Policy |
| 9 | +------------------- |
| 10 | + |
| 11 | +Starting with Node 8, CSS Blocks and related projects will support all |
| 12 | +[Active LTS releases of Node][node-releases]. Once a node version moves into |
| 13 | +"Maintenance LTS" we reserve the right to drop support for it with the next |
| 14 | +*minor* release. Our projects are configured to set the node `engine` version |
| 15 | +in their `package.json`, so such releases will not regress for projects using |
| 16 | +older versions of node — but bug fixes and new features may not be |
| 17 | +released. |
| 18 | + |
| 19 | +The exception to this is that critical security patches will be released for |
| 20 | +versions of our software to support projects using Node that remains in the |
| 21 | +Maintenance LTS mode. |
| 22 | + |
| 23 | +Code Style |
| 24 | +---------- |
| 25 | + |
| 26 | +1. Code is written in TypeScript and transpiled to the newest version of ES |
| 27 | + Modules that are supported by our Node Support Policy (see above). |
| 28 | +2. All TypeScript code will use this project's configuration |
| 29 | + files where possible. |
| 30 | +3. Linting must be performed as part of `yarn test` for every node package. |
| 31 | +4. All code is compiled with TypeScript's strictest settings enabled and |
| 32 | + any new strictness options are enabled with each TypeScript release. |
| 33 | +5. Specific Lint rules ran are not covered here. The source of truth is |
| 34 | + the [`tslint.json`][tsconfig-file] file. |
| 35 | +6. Avoid `any`. There are very few times it's necessary. We use |
| 36 | + the type `something` from `@opticss/util` to express very generic |
| 37 | + values without introducing the infectious semantics of `any`. |
| 38 | + Exceptions: |
| 39 | + a. [Type guards][type-guards] can accept an argument of type `any`. |
| 40 | + b. Callbacks whose return value is not consumed can have a declared |
| 41 | + return value of `any`. |
| 42 | + |
| 43 | +Test Code Style |
| 44 | +--------------- |
| 45 | + |
| 46 | +Test code is linted like source code. Exceptions and Additions to those rules |
| 47 | +are listed here: |
| 48 | + |
| 49 | +1. Testing is done with [`ts-mocha`][ts-mocha], [`chai`][chai] for assertions. |
| 50 | +2. Do not use "bdd-style" assertions (e.g. expect/should) for tests. |
| 51 | +3. Tests that use randomization or fuzzing to test a feature must |
| 52 | + include information in the output or error that makes it easy to reproduce |
| 53 | + the error either by seeding the random number generator or by including |
| 54 | + the actual values used in the error message. |
| 55 | +4. Integration testing is preferred to unit tests so that tests are robust |
| 56 | + against internal refactors. |
| 57 | +5. When unit testing, there is a preference for adding internal APIs to real |
| 58 | + objects over using mocks/stubs or other tools to inspect that a test had the |
| 59 | + expected outcomes to its unit and to the units it interacts with. |
| 60 | + |
| 61 | +Editor/IDE |
| 62 | +---------- |
| 63 | + |
| 64 | +This project recommends the use of Visual Studio Code and includes |
| 65 | +configuration for integration with it to enhance the IDE experience |
| 66 | +with the tooling choices of the project and makes things like |
| 67 | +interactive debugging work easily while running the tests. |
| 68 | + |
| 69 | + |
| 70 | +[node-releases]: https://github.com/nodejs/Release |
| 71 | +[tsconfig-file]: https://github.com/css-blocks/css-blocks/tree/master/packages/code-style/configs/tslint.json |
| 72 | +[type-guards]: https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types |
| 73 | +[ts-mocha]: https://www.npmjs.com/package/ts-mocha |
| 74 | +[chai]: http://chaijs.com/api/assert/ |
0 commit comments