justintime50-styles 0.11.3 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -2
- package/README.md +28 -36
- package/composer.json +3 -3
- package/package.json +1 -1
- package/src/python/pyproject.toml +3 -12
- package/src/ruby/.rubocop.yaml +0 -1
- package/src/python/.flake8 +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
-
## v0.
|
|
3
|
+
## v0.12.0 (2026-03-18)
|
|
4
4
|
|
|
5
|
-
- Bumps `phpcs-short-scalar-types`
|
|
5
|
+
- Bumps `justintime50/phpcs-short-scalar-types`
|
|
6
|
+
- Removes `TargetRubyVersion` in rubocop.yaml
|
|
7
|
+
- Bumps deps
|
|
8
|
+
|
|
9
|
+
## v0.11.2, v0.11.3, v0.11.4 (2026-01-03)
|
|
10
|
+
|
|
11
|
+
- Bumps `phpcs-short-scalar-types` so it can now be auto-installed with `PHPCSStandards/composer-installer`, various updates to `phpcs-short-scalar-types`
|
|
6
12
|
|
|
7
13
|
## v0.11.1 (2026-01-03)
|
|
8
14
|
|
package/README.md
CHANGED
|
@@ -5,11 +5,9 @@ A collection of style guides and best practices used for my projects and teams.
|
|
|
5
5
|
[](https://github.com/Justintime50/styles/actions)
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
|
|
8
|
-
This document is fluid and many changes will be coming over the next few months as I collect more information to include here. By the time I'm finished, I'd love the final product to look something like: <https://codeguide.co/>
|
|
9
|
-
|
|
10
8
|
## Tooling Configuration
|
|
11
9
|
|
|
12
|
-
You can find various configuration files for styling/formatting tools across various langauges found in the `
|
|
10
|
+
You can find various configuration files for styling/formatting tools across various langauges found in the `src` directory.
|
|
13
11
|
|
|
14
12
|
### NPM Install
|
|
15
13
|
|
|
@@ -27,11 +25,6 @@ composer require --dev justintime50/styles
|
|
|
27
25
|
|
|
28
26
|
### Architecture
|
|
29
27
|
|
|
30
|
-
- Simple Design:
|
|
31
|
-
- Runs all the tests
|
|
32
|
-
- Contains no duplication
|
|
33
|
-
- Expresses the intent of the programmer
|
|
34
|
-
- Minimizes the number of classes and methods
|
|
35
28
|
- Build out clean interfaces over ad-hoc scripts or SQL queries. This will ensure consistency, safety, and it can be code reviewed
|
|
36
29
|
- Separate constructing a system from using it, meaning that the “setup” code should be separate from the main business logic
|
|
37
30
|
- Abstract your data structures. Abstract interfaces allow its users to manipulate the essence of the data without having to know how it’s implemented
|
|
@@ -47,31 +40,32 @@ composer require --dev justintime50/styles
|
|
|
47
40
|
### Checklist
|
|
48
41
|
|
|
49
42
|
- Ensure the code you are writing is `NULL` safe
|
|
50
|
-
- Ensure the code you are writing either has a unit test (especially when you need to guard against a regression) or that you have end-to-end tested it. Preferably, you would
|
|
43
|
+
- Ensure the code you are writing either has a unit test (especially when you need to guard against a regression) or that you have end-to-end tested it. Preferably, you would do both
|
|
51
44
|
- Ensure the code is readable, remember, you will have other contributors looking at this in the future, maybe even years later
|
|
52
45
|
- Will it make sense then as it does now?
|
|
53
|
-
- Ensure your code is
|
|
46
|
+
- Ensure your code is easy to maintain. Can things be added to this easily, can we tweak the configuration if requirements change in the future, does it make sense enough that someone with no context could jump in later on and work on this?
|
|
54
47
|
- Ensure your code preserves git blame (eg: Trailing commas, breaking up lists to different lines)
|
|
55
48
|
- Ensure your code is self documenting (eg: function and variable names give a clear indicator to the reader of what is happening and what it is doing)
|
|
56
49
|
- Ensure your code does not introduce side effects. Functions and classes should do one thing without bleeding into other areas
|
|
57
50
|
|
|
58
51
|
### Classes
|
|
59
52
|
|
|
60
|
-
- Class variables should be listed public static constants first, then private static variables, followed by private instance variables. There is seldom reason to have a public variable
|
|
53
|
+
- Class variables should be listed public static constants first, then private static variables, followed by private instance variables. There is seldom reason to have a public (global) variable
|
|
61
54
|
- The name of a class should describe what responsibilities it fulfills
|
|
62
55
|
- You should be able to define a class in 25 words or less without using the words “if”, “and”, “or”, or “but”, otherwise it probably has too many responsibilities
|
|
63
|
-
- SPR: Single Responsibility Principle
|
|
56
|
+
- SPR: **Single Responsibility Principle**, classes should only ever do one thing. A “dashboard” class shouldn’t grab the version number and show stats for your app
|
|
64
57
|
- Break out the version data into a separate class
|
|
65
58
|
- Programs should be made up of many small classes
|
|
66
|
-
- OCP: Open-Closed Principle
|
|
67
|
-
- DIP: Dependency Inversion Principle
|
|
68
|
-
- Using instance variables is a powerful way to cut down on passing large amounts of parameters around your app when everything is stored within the `self` namespace, it can be easily referenced from any instance method and seemingly numberless variables can be associated with `self`
|
|
59
|
+
- OCP: **Open-Closed Principle**, classes are open to extension but closed to modification
|
|
60
|
+
- DIP: **Dependency Inversion Principle**, classes should depend on abstractions, not concrete details
|
|
61
|
+
- Using instance variables is a powerful way to cut down on passing large amounts of parameters around your app when everything is stored within the `self` namespace, it can be easily referenced from any instance method and seemingly numberless variables can be associated with `self`
|
|
69
62
|
|
|
70
63
|
### Comments
|
|
71
64
|
|
|
72
65
|
- Comments should be used when we fail to express properly our intentions in code
|
|
73
|
-
- Comments should explain why we did what we did
|
|
66
|
+
- Comments should explain **why** we did what we did, the code should be self-documenting enough to define the **what**. If we need to define what code does with a comment, the code should probably be refactored
|
|
74
67
|
- Comments can live for years, make sure they’ll age well hundreds of commits later
|
|
68
|
+
- Comments should not be used needlessly and instead should seldomly be used
|
|
75
69
|
|
|
76
70
|
### Concurrency
|
|
77
71
|
|
|
@@ -87,18 +81,17 @@ composer require --dev justintime50/styles
|
|
|
87
81
|
|
|
88
82
|
### Databases
|
|
89
83
|
|
|
90
|
-
- All inserts/updates must be run inside a transaction. Validate your change before committing it.
|
|
84
|
+
- All manual inserts/updates must be run inside a transaction (eg: `BEGIN`, `COMMIT`, `ROLLBACK`). Validate your change before committing it.
|
|
85
|
+
- Many inserts/updates/deletes should not be done sequentially for performance. Batch them in groups of ~1000 records.
|
|
91
86
|
|
|
92
87
|
### Error Handling
|
|
93
88
|
|
|
94
|
-
-
|
|
95
|
-
- Error handling should be in its own function if we are following the “functions do one thing” rule
|
|
89
|
+
- Errors should bubble up from functions, allowing the calling code to determine what to do with it
|
|
96
90
|
- If error handling obscures logic, it’s wrong
|
|
97
91
|
|
|
98
92
|
### Functions
|
|
99
93
|
|
|
100
|
-
- Have a single return statement (
|
|
101
|
-
- Return statements should have a line break betwen them and the content above to clearly define the function is now complete and to separate focuses
|
|
94
|
+
- Have a single return statement (avoid returning early)
|
|
102
95
|
- Avoid returning null, avoid passing null as a parameter
|
|
103
96
|
- Avoid using class methods where possible and instead use instance or static methods.
|
|
104
97
|
- Don’t use “selector arguments” or booleans for arguments to a function because this breaks the single responsibility principle. If your function does something different depending on a Boolean parameter, it really does two things and therefore the name will be misleading. Instead, you should break up the function into smaller functions, each doing one branch of the boolean flag
|
|
@@ -131,10 +124,9 @@ def is_number_large(my_number, threshold = 100):
|
|
|
131
124
|
|
|
132
125
|
- Put all instance variables at the top of your file, don’t mix them with public functions
|
|
133
126
|
- “Main” functions should be declared first in a file so that you can then keep reading from top to bottom as you drill down
|
|
134
|
-
-
|
|
135
|
-
- Line lengths should not exceed 120 chars
|
|
127
|
+
- Line lengths should not exceed 120 characters for readability
|
|
136
128
|
- Use trailing commas where possible so that the list can easily grow in the future while keeping the next diff small
|
|
137
|
-
- Create a consistent lexicon and share it across the company for things like names (eg: fetch, get, retrieve all ultimately mean the same thing, which will you use across your code base?). If you do something someway, do it that way everywhere. This leans back to the principle of least surprise
|
|
129
|
+
- Create a consistent lexicon and share it across the company for things like names (eg: "fetch", "get", "retrieve" all ultimately mean the same thing, which will you use across your code base?). If you do something someway, do it that way everywhere. This leans back to the principle of least surprise
|
|
138
130
|
- Don’t pack lists or block pack them, always unpack lists so that each item is on its own line. It’s easier to read vertically than it is horizontally
|
|
139
131
|
- Use object literals over complex if/else or switch/case statements
|
|
140
132
|
- Use implicit true statements when possible (eg: `if im_awesome is True:` — vs — `if im_awesome:`)
|
|
@@ -142,10 +134,13 @@ def is_number_large(my_number, threshold = 100):
|
|
|
142
134
|
- Always sort your lists unless there is an explicit reason not to. This ensures that diffs stay small and sorted lists are much easier to maintain and find info in
|
|
143
135
|
- Positives are easier to understand than negatives, in the case of if/else statements, have the “if” section be the positive logic
|
|
144
136
|
- Don’t include dead code. This could be code in an if/else block that will never be reached or code in a try/except block that can never throw
|
|
137
|
+
- Don't include commented out code. It's never run, it bloates the software, and if it existed before and we are commenting out "for now", it still exists in git history. It should be removed
|
|
145
138
|
- Think of “vertical separation”, variables and functions should be defined close to where they are used, not hundreds of lines apart
|
|
146
139
|
- General purpose static functions should not be contained in a class since they typically aren’t actually coupled to the class
|
|
147
140
|
- Shoot for brevity, be precise! Don’t use a float for currency (break it down into an integer for "cents"), don’t avoid adding lock/transaction management on concurrency, etc - “Don’t be lazy about the precision of your decision”
|
|
148
|
-
- Avoid words like `filter` when naming
|
|
141
|
+
- Avoid words like `filter` when naming things because it can either mean `filter out` or `filter in`
|
|
142
|
+
- Projects should be placed in a top-level `src` folder so that project config and documents can live outside the project folder
|
|
143
|
+
- Target versions of a language back to the the oldest maintained version up through the newest version where possible. Drop support for versions of a language that no longer receive maintenance (security updates, etc) and adopt new versions as early as is feasible
|
|
149
144
|
|
|
150
145
|
### Naming
|
|
151
146
|
|
|
@@ -153,11 +148,6 @@ def is_number_large(my_number, threshold = 100):
|
|
|
153
148
|
- Abbreviating or coming up with clever names only leads to more taxing code scanning by the next engineer
|
|
154
149
|
- Use constants or variables to define integers and other strings that aren’t easily identifiable (vs just passing them inline as parameters without declaring what they are). A great example of a snippet of code where this could be useful is instead of directly returning the following, you could assign it a descriptive variable and return that clean variable instead: `{k: cls._objects_to_ids(v) for k, v in six.iteritems(params)}`. This also goes for having multiple and/or statements, assign them to a variable to help describe intent
|
|
155
150
|
|
|
156
|
-
### Open Source
|
|
157
|
-
|
|
158
|
-
- Projects should be placed in a top-level `src` folder so that project config and documents can live outside the project folder
|
|
159
|
-
- Target versions of a language back to the the oldest maintained version up through the newest version where possible. Drop support for versions of a language that no longer receive maintenance (security updates, etc) and adopt new versions as early as is feasible
|
|
160
|
-
|
|
161
151
|
### Testing
|
|
162
152
|
|
|
163
153
|
- Clean tests follow five rules:
|
|
@@ -168,7 +158,7 @@ def is_number_large(my_number, threshold = 100):
|
|
|
168
158
|
- Timely: tests should be written shortly before the production code they’ll be testing
|
|
169
159
|
- Unit tests should follow the Build-Operate-Check model where test data is built, then the function is operated, and finally the result is asserted against an expectation. Don’t add extra noise to tests
|
|
170
160
|
- Test only a single concept per unit test
|
|
171
|
-
- Don’t mock to make yourself feel better; mock because you have to
|
|
161
|
+
- Don’t mock to make yourself feel better; mock because you have to. Mocks don't run real production code, they make believe and call it a test
|
|
172
162
|
|
|
173
163
|
## Language Specific
|
|
174
164
|
|
|
@@ -216,7 +206,7 @@ The following is a checklist of items that every website should have:
|
|
|
216
206
|
|
|
217
207
|
- Don't repeat ` ` over and over when you want to space something, use a CSS class in a `<span>` to do this instead
|
|
218
208
|
- Avoid using inline CSS styles (use CSS classes and external stylesheets)
|
|
219
|
-
- `<br />` tags should only be contained inside a set of `<p>` tags. CSS classes should
|
|
209
|
+
- `<br />` tags should only be contained inside a set of `<p>` tags. CSS classes should be used otherwise to provide vertical spacing
|
|
220
210
|
- Always list the `href/src` first for stylesheets and scripts for easy readability and visual scanning (eg: `<a href="https://example.com" target="_blank">example</a>`)
|
|
221
211
|
- `rel` is required for stylesheets
|
|
222
212
|
|
|
@@ -240,6 +230,7 @@ The following is a checklist of items that every website should have:
|
|
|
240
230
|
|
|
241
231
|
#### Java Tools
|
|
242
232
|
|
|
233
|
+
- **Dependency Management:** [maven](https://github.com/apache/maven)
|
|
243
234
|
- **Linter:** [Checkstyle](https://github.com/checkstyle/checkstyle)
|
|
244
235
|
- **Static Analysis:** [Error Prone](https://github.com/google/error-prone)
|
|
245
236
|
- **VCR:** [EasyVCR](https://github.com/EasyPost/easyvcr-java)
|
|
@@ -248,6 +239,7 @@ The following is a checklist of items that every website should have:
|
|
|
248
239
|
|
|
249
240
|
#### Javascript Tools
|
|
250
241
|
|
|
242
|
+
- **Dependency Management:** [npm](https://github.com/npm/cli)
|
|
251
243
|
- **Formatter:** [Prettier](https://prettier.io)
|
|
252
244
|
- Config file found in this repo: `.prettierrc.yml`
|
|
253
245
|
- **Linter:** [ESLint](https://github.com/eslint/eslint)
|
|
@@ -259,6 +251,7 @@ The following is a checklist of items that every website should have:
|
|
|
259
251
|
|
|
260
252
|
#### PHP Tools
|
|
261
253
|
|
|
254
|
+
- **Dependency Management:** [composer](https://github.com/composer/composer)
|
|
262
255
|
- **Linter:** [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
|
|
263
256
|
- **Tests:** [PHPUnit](https://github.com/sebastianbergmann/phpunit)
|
|
264
257
|
- **VCR:** [PHP VCR](https://github.com/php-vcr/php-vcr)
|
|
@@ -267,11 +260,9 @@ The following is a checklist of items that every website should have:
|
|
|
267
260
|
|
|
268
261
|
#### Python Tools
|
|
269
262
|
|
|
270
|
-
- **
|
|
263
|
+
- **Dependency Management:** [uv](https://github.com/astral-sh/uv)
|
|
264
|
+
- **Linter/Formatter:** [Ruff](https://github.com/astral-sh/ruff)
|
|
271
265
|
- Config file found in this repo: `pyproject.toml`
|
|
272
|
-
- **Import Sorter:** [iSort](https://github.com/PyCQA/isort)
|
|
273
|
-
- **Linter:** [Flake8](https://github.com/PyCQA/flake8)
|
|
274
|
-
- Config file found in this repo: `.flake8`
|
|
275
266
|
- **Security:** [Bandit](https://github.com/PyCQA/bandit)
|
|
276
267
|
- **Static Analysis:** [mypy](https://github.com/python/mypy)
|
|
277
268
|
- **Tests:** [Pytest](https://github.com/pytest-dev/pytest)
|
|
@@ -318,6 +309,7 @@ assert str(error.value) == 'You sent bad input'
|
|
|
318
309
|
|
|
319
310
|
#### Ruby Tools
|
|
320
311
|
|
|
312
|
+
- **Dependency Management:** [rubygems](https://github.com/ruby/rubygems)
|
|
321
313
|
- **Linter:** [RuboCop](https://github.com/rubocop-hq/rubocop)
|
|
322
314
|
- **Security:** [Brakeman](https://github.com/presidentbeef/brakeman)
|
|
323
315
|
- **Tests:** [RSpec](https://github.com/rspec/rspec)
|
package/composer.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "justintime50/styles",
|
|
3
3
|
"description": "A collection of style guides and best practices used for my projects and teams.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "library",
|
|
7
7
|
"homepage": "https://github.com/Justintime50/styles",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
],
|
|
14
14
|
"require": {
|
|
15
15
|
"php": "^8.0",
|
|
16
|
-
"justintime50/phpcs-short-scalar-types": "^0.
|
|
17
|
-
"slevomat/coding-standard": "^8.
|
|
16
|
+
"justintime50/phpcs-short-scalar-types": "^1.0.0",
|
|
17
|
+
"slevomat/coding-standard": "^8.28"
|
|
18
18
|
},
|
|
19
19
|
"config": {
|
|
20
20
|
"allow-plugins": {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "justintime50-styles",
|
|
3
3
|
"description": "A collection of style guides and best practices used for my projects and teams.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"author": "Justintime50",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/justintime50/styles",
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
[tool.
|
|
2
|
-
preview = true
|
|
1
|
+
[tool.ruff]
|
|
3
2
|
line-length = 120
|
|
4
3
|
|
|
5
|
-
[tool.
|
|
6
|
-
|
|
7
|
-
line_length = 120
|
|
8
|
-
indent = 4
|
|
9
|
-
force_grid_wrap = 2
|
|
10
|
-
multi_line_output = 3
|
|
11
|
-
sections = "FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER"
|
|
12
|
-
lines_after_imports = 2
|
|
13
|
-
include_trailing_comma = true
|
|
14
|
-
use_parentheses = true
|
|
4
|
+
[tool.mypy]
|
|
5
|
+
disable_error_code = "import-untyped"
|
package/src/ruby/.rubocop.yaml
CHANGED
package/src/python/.flake8
DELETED