Skip to content

Commit c361bc0

Browse files
committed
chore(lint): Introduce shared lint configuration and initial code style documentation.
1 parent 5b28b71 commit c361bc0

File tree

20 files changed

+430
-131
lines changed

20 files changed

+430
-131
lines changed

commitlint.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
rules: {
4+
'subject-full-stop': [2, 'always', '.'],
5+
'subject-case': [
6+
2, 'always',
7+
['sentence-case']
8+
]
9+
}
10+
}

css-blocks.code-workspace

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"path": "packages/webpack-plugin"
1717
},
1818
{
19-
"path": "packages/webpack-plugin"
19+
"path": "packages/code-style"
2020
}
2121
],
2222
"settings": {

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"private": true,
3-
<<<<<<< HEAD
3+
"scripts": {
4+
"commitmsg": "commitlint -e $GIT_PARAMS"
5+
},
46
"devDependencies": {
7+
"@commitlint/cli": "^6.1.0",
8+
"@commitlint/config-conventional": "^6.1.0",
9+
"husky": "^0.14.3",
510
"lerna": "^2.5.1"
611
},
7-
=======
8-
"devDependencies": {
9-
"lerna": "^2.5.1"
10-
},
11-
>>>>>>> 65ec8b6... Squash with 4420cd6e5efaf53b5c9ae2a2c4bfd82407cb4373
1212
"workspaces": [
1313
"packages/*"
1414
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"cSpell.words": [
3+
"transpiled"
4+
]
5+
}

packages/code-style/README.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 &mdash; 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/
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"rules": {
3+
"curly": false,
4+
"no-var-keyword": true,
5+
"adjacent-overload-signatures": true,
6+
"no-for-in-array":true,
7+
"no-unsafe-any": {
8+
"severity": "warn"
9+
},
10+
"indent": [true, "spaces"],
11+
"label-position": true,
12+
"no-consecutive-blank-lines": [
13+
true
14+
],
15+
"no-construct": true,
16+
"no-debugger": true,
17+
"no-duplicate-variable": true,
18+
"no-inferrable-types": [true],
19+
"no-trailing-whitespace": true,
20+
"no-unused-expression": true,
21+
"semicolon": [true, "always"],
22+
"triple-equals": true,
23+
"class-name": true,
24+
"no-default-export": {
25+
"severity": "warn"
26+
}
27+
}
28+
}

packages/code-style/package.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@css-blocks/code-style",
3+
"version": "0.17.0",
4+
"main": "configs/tslint.json",
5+
"readme": "README.md",
6+
"bugs": {
7+
"url": "https://github.com/css-blocks/css-blocks/issues"
8+
},
9+
"repository": {
10+
"url": "https://github.com/css-blocks/css-blocks.git",
11+
"type": "git"
12+
},
13+
"homepage": "https://github.com/css-blocks/css-blocks/tree/master/packages/code-style"
14+
}

packages/css-blocks/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"main": "dist/src/index.js",
66
"scripts": {
77
"compile": "rm -rf dist && tsc -p test/tsconfig.json",
8-
"pretest": "npm run compile && tslint --project tsconfig.json --type-check",
8+
"pretest": "npm run compile && tslint --project tsconfig.json",
99
"prepublish": "npm run compile",
10-
"tslint": "tslint --project tsconfig.json",
10+
"lint": "tslint --project tsconfig.json",
1111
"test": "mocha dist/test --opts test/mocha.opts",
1212
"coverage": "istanbul cover -i \"dist/src/**/*.js\" --dir ./build/coverage node_modules/.bin/_mocha -- dist/test --opts test/mocha.opts",
1313
"remap": "remap-istanbul -i build/coverage/coverage.json -o coverage -t html",
@@ -35,6 +35,7 @@
3535
],
3636
"homepage": "https://github.com/css-blocks/css-blocks/tree/master/packages/css-blocks#readme",
3737
"devDependencies": {
38+
"@css-blocks/code-style": "^0.17.0",
3839
"@opticss/util": "^0.1.1",
3940
"@types/chai": "^3.5.2",
4041
"@types/mocha": "^2.2.41",

packages/css-blocks/tslint.json

+1-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
11
{
2-
"rules": {
3-
"curly": false,
4-
"no-var-keyword": true,
5-
"indent": [true, "spaces"],
6-
"label-position": true,
7-
"no-consecutive-blank-lines": [
8-
true
9-
],
10-
"no-construct": true,
11-
"no-debugger": true,
12-
"no-duplicate-variable": true,
13-
"no-inferrable-types": [true],
14-
"no-trailing-whitespace": true,
15-
"no-unused-variable": true,
16-
"no-unused-expression": true,
17-
"semicolon": [true, "always"],
18-
"triple-equals": true,
19-
"class-name": true
20-
}
2+
"extends": "@css-blocks/code-style"
213
}

packages/glimmer-templates/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"scripts": {
1313
"test": "mocha --opts test/mocha.opts dist/test",
1414
"compile": "rm -rf dist && tsc -p test/tsconfig.json",
15-
"pretest": "npm run compile && npm run tslint",
15+
"pretest": "npm run compile && npm run lint",
1616
"prepublish": "npm run compile",
17-
"tslint": "tslint --project tsconfig.json --type-check",
17+
"lint": "tslint --project tsconfig.json",
1818
"coverage": "istanbul cover -i dist/src/**/*.js --dir ./build/coverage node_modules/mocha/bin/_mocha -- dist/test --opts test/mocha.opts",
1919
"remap": "remap-istanbul -i build/coverage/coverage.json -o coverage -t html",
2020
"docs": "typedoc --out ./docs .",
@@ -43,6 +43,7 @@
4343
},
4444
"homepage": "https://github.com/css-blocks/css-blocks/tree/master/packages/glimmer-templates#readme",
4545
"devDependencies": {
46+
"@css-blocks/code-style": "^0.17.0",
4647
"@types/chai": "^3.5.2",
4748
"@types/debug": "0.0.29",
4849
"@types/mocha": "^2.2.41",
+1-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
11
{
2-
"rules": {
3-
"curly": false,
4-
"no-var-keyword": true,
5-
"indent": [true, "spaces"],
6-
"label-position": true,
7-
"no-consecutive-blank-lines": [
8-
true
9-
],
10-
"no-construct": true,
11-
"no-debugger": true,
12-
"no-duplicate-variable": true,
13-
"no-inferrable-types": [true],
14-
"no-trailing-whitespace": true,
15-
"no-unused-variable": true,
16-
"no-unused-expression": true,
17-
"semicolon": [true, "always"],
18-
"triple-equals": true,
19-
"class-name": true
20-
}
2+
"extends": "@css-blocks/code-style"
213
}

packages/jsx/.vscode/settings.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
"opticss",
1010
"truthy"
1111
],
12+
"cSpell.ignorePaths": [
13+
"**/node_modules/**",
14+
"**/vscode-extension/**",
15+
"**/.git/**",
16+
".vscode",
17+
"typings",
18+
"package.json"
19+
],
1220
"tslint.packageManager": "yarn",
13-
"npm.packageManager": "yarn"
21+
"npm.packageManager": "yarn",
22+
"tslint.enable": true
1423
}

packages/jsx/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
"dist"
99
],
1010
"scripts": {
11-
"pretest": "npm run build && npm run tslint",
11+
"pretest": "npm run build && npm run lint",
1212
"test": "mocha dist/test --recursive --opts test/mocha.opts",
1313
"build": "rm -rf dist && tsc --jsx preserve -p tsconfig.json",
1414
"prepublish": "npm run build",
1515
"watch": "watch 'npm run test' './src' './test' --wait=3",
16-
"tslint": "tslint --project tsconfig.json --type-check"
16+
"lint": "tslint --project tsconfig.json"
1717
},
1818
"repository": {
1919
"type": "git",
@@ -34,6 +34,7 @@
3434
},
3535
"homepage": "https://github.com/css-blocks/css-blocks/tree/master/packages/jsx#readme",
3636
"devDependencies": {
37+
"@css-blocks/code-style": "^0.17.0",
3738
"@css-blocks/runtime": "^0.17.0",
3839
"@types/babel-core": "^6.25.2",
3940
"@types/babel-generator": "^6.25.0",

packages/jsx/src/transformer/babel.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ const CAN_PARSE_EXTENSIONS = {
5050
'.jsx': true,
5151
};
5252

53-
export default function mkTransform(tranformOpts: { rewriter: Rewriter }): () => PluginObj<CssBlocksVisitor> {
54-
const rewriter = tranformOpts.rewriter;
53+
export default function mkTransform(transformOpts: { rewriter: Rewriter }): () => PluginObj<CssBlocksVisitor> {
54+
const rewriter = transformOpts.rewriter;
5555

5656
return function transform(): PluginObj<CssBlocksVisitor> {
5757

packages/jsx/tslint.json

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
11
{
2-
"rules": {
3-
"curly": false,
4-
"no-var-keyword": true,
5-
"indent": [ true, "spaces" ],
6-
"label-position": true,
7-
"no-consecutive-blank-lines": [ true ],
8-
"no-construct": true,
9-
"no-debugger": true,
10-
"no-duplicate-variable": true,
11-
"no-inferrable-types": [true],
12-
"no-trailing-whitespace": true,
13-
"no-unused-expression": true,
14-
"no-unused-variable": true,
15-
"semicolon": [ true, "always" ],
16-
"triple-equals": true,
17-
"class-name": true,
18-
"quotemark": [ true, "single", "jsx-double", "avoid-escape" ]
19-
}
2+
"extends": "@css-blocks/code-style"
203
}

packages/runtime/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"dist"
99
],
1010
"scripts": {
11-
"pretest": "npm run build && npm run tslint",
11+
"pretest": "npm run build && npm run lint",
1212
"test": "echo 'tested in @css-blocks/jsx'",
1313
"build": "rm -rf dist && tsc",
1414
"prepublish": "npm run build",
15-
"tslint": "tslint --project tsconfig.json"
15+
"lint": "tslint --project tsconfig.json"
1616
},
1717
"repository": {
1818
"type": "git",
@@ -28,6 +28,7 @@
2828
},
2929
"homepage": "https://github.com/css-blocks/css-blocks/tree/master/packages/runtime/#readme",
3030
"devDependencies": {
31+
"@css-blocks/code-style": "^0.17.0",
3132
"grunt": "^1.0.1",
3233
"grunt-release": "^0.12.0",
3334
"tslint": "^5.5.0",

packages/runtime/tslint.json

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
11
{
2-
"rules": {
3-
"curly": false,
4-
"no-var-keyword": true,
5-
"indent": [ true, "spaces" ],
6-
"label-position": true,
7-
"no-consecutive-blank-lines": [ true ],
8-
"no-construct": true,
9-
"no-debugger": true,
10-
"no-duplicate-variable": true,
11-
"no-inferrable-types": [true],
12-
"no-trailing-whitespace": true,
13-
"no-unused-expression": true,
14-
"no-unused-variable": true,
15-
"semicolon": [ true, "always" ],
16-
"triple-equals": true,
17-
"class-name": true,
18-
"quotemark": [ true, "single", "jsx-double", "avoid-escape" ]
19-
}
2+
"extends": "@css-blocks/code-style"
203
}

packages/webpack-plugin/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"prepublish": "tsc -p tsconfig.json",
88
"pretest": "tsc -p tsconfig.json && tslint --project tsconfig.json",
9-
"tslint": "tslint --project tsconfig.json",
9+
"lint": "tslint --project tsconfig.json",
1010
"test": "mocha dist/test --opts test/mocha.opts",
1111
"coverage": "istanbul cover -i dist/src/**/*.js --dir ./build/coverage node_modules/mocha/bin/_mocha -- dist/test --opts test/mocha.opts",
1212
"remap": "remap-istanbul -i build/coverage/coverage.json -o coverage -t html",
@@ -33,6 +33,7 @@
3333
],
3434
"homepage": "https://github.com/css-blocks/css-blocks/tree/master/packages/webpack-plugin#readme",
3535
"devDependencies": {
36+
"@css-blocks/code-style": "^0.17.0",
3637
"@types/async": "^2.0.40",
3738
"@types/chai": "^3.5.2",
3839
"@types/convert-source-map": "^1.3.33",

0 commit comments

Comments
 (0)