Skip to content

Commit 1ab80fd

Browse files
Add prefer_extracted_top_level_constant analyzer comment (#2368)
* Add prefer_extracted_top_level_constant analyzer comment to javascript resistor color duo (exercism/javascript-analyzer#127) * Format analyzer-comments/javascript/resistor-color-duo/prefer_extracted_top_level_constant.md Co-authored-by: Derk-Jan Karrenbeld <[email protected]> * add exported method to prefer_extracted_top_level_constant in js resistor_color_duo --------- Co-authored-by: Derk-Jan Karrenbeld <[email protected]>
1 parent 8b47b7a commit 1ab80fd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# prefer extracted top level constant
2+
3+
Consider extracting the constant to the top level scope:
4+
5+
```javascript
6+
const %{name} = %{value}
7+
8+
// the rest of your code below it
9+
export %{method.signature}
10+
```
11+
12+
Only functions, classes and constants that are `export`ed, are visible and accessible from the outside.
13+
These constants can live in the same file without being exposed to other code.
14+
Also, extracting constants saves memory by avoiding repeated allocations in functions when those same constants are reused.

0 commit comments

Comments
 (0)