Skip to content

Commit 576ed21

Browse files
author
James Allardice
committed
Added JSHint camelcase option article
1 parent 0a66266 commit 576ed21

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!---
2+
{
3+
"titles": [
4+
"camelcase"
5+
],
6+
"slugs": [
7+
"option-jshint-camelcase"
8+
],
9+
"linters": [
10+
"jshint"
11+
],
12+
"author": "jallardice",
13+
"subject": "option"
14+
}
15+
-->
16+
17+
### What does this option do?
18+
19+
The JSHint `camelcase` option is used to force all identifiers (function,
20+
variable and property) to either be written in camel case or in uppercase with
21+
underscores. It's common convention in JavaScript to use camel case for normal
22+
identifiers and uppercase for identifiers that represent constants. In the
23+
following example we have a couple of identifiers that break the camel case
24+
rule:
25+
26+
<!---
27+
{
28+
"linter": "jshint"
29+
}
30+
-->
31+
```javascript
32+
/*jshint camelcase: true */
33+
var camel_case = 1;
34+
var fake_constant = 2;
35+
var obj = {
36+
not_good: 3
37+
};
38+
```
39+
40+
In the next example we've changed the identifiers so they conform to the rules:
41+
42+
<!---
43+
{
44+
"linter": "jshint"
45+
}
46+
-->
47+
```javascript
48+
/*jshint camelcase: true */
49+
var camelCase = 1;
50+
var FAKE_CONSTANT = 2;
51+
var obj = {
52+
notGood: 3
53+
};
54+
```
55+
56+
### When should I use this option?
57+
58+
The use of the `camelcase` JSHint option will cause an "Identifier '{a}' is not
59+
in camel case" error, where "{a}" is the identifier in question, any time it
60+
encounters an identifier that doesn't match the rules discussed above. You
61+
should only enable this option when you want to enforce a coding style
62+
throughout your program. This is generally a good idea when you're working on a
63+
project with multiple developers to help keep things consistent.
64+
65+
Note that this is an *enforcing* option which means JSHint does not apply it by
66+
default. If you do not explicitly set this option to `true` JSHint will allow
67+
the use of bitwise operators anywhere in your code.

0 commit comments

Comments
 (0)