/
quotes.js
49 lines (41 loc) · 993 Bytes
/
quotes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import CoreRule from '../../core/rule.js';
/**
* Quotes
*
* Use single quotes instead of double quotes.
*
* @see https://prettier.io/docs/en/options.html#quotes
*/
export default class RuleQuotes extends CoreRule
{
/**
* @var boolean
*/
get default() {
return false;
}
/**
* @var string
*/
get property() {
return 'singleQuote';
}
/**
* Mandatory entry function to create a decision
*
* @return boolean
*/
identify() {
let output = this.default;
// Find count of all our quotes
const singleQuotes = [...this.input.matchAll(/'/gm)];
const doubleQuotes = [...this.input.matchAll(/"/gm)];
// No quotes found
if (singleQuotes.length === 0 && doubleQuotes.length === 0) {
return this.default;
}
// Logic for quotes leans single
output = singleQuotes.length >= doubleQuotes.length;
return output;
}
}