• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

coderaiser / putout / 10575639235

27 Aug 2024 09:39AM CUT coverage: 100.0%. Remained the same
10575639235

push

github

coderaiser
chore: @putout/plugin-putout-config: v6.2.0

9651 of 9651 branches covered (100.0%)

Branch coverage included in aggregate %.

37669 of 37669 relevant lines covered (100.0%)

18513.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/codemods/convert-pascal-to-camel/lib/pascal-to-camel.js
1
import {operator} from 'putout';
3✔
2

3✔
3
const {rename} = operator;
3✔
4

3✔
5
export const report = (path) => `Use camelCase instead of PascalCase in functions ${path.node.name}`;
3✔
6

3✔
7
export const fix = (path) => {
3✔
8
    const {name} = path.node;
30✔
9
    
30✔
10
    path.node.name = toCamel(name);
30✔
11
    rename(path, name, toCamel(name));
30✔
12
};
3✔
13

3✔
14
export const traverse = ({push}) => ({
3✔
15
    ClassProperty: checkBig('key', push),
18✔
16
    ClassMethod: checkBig('key', push),
18✔
17
    FunctionDeclaration: checkBig('id', push),
18✔
18
    
18✔
19
    FunctionExpression(path) {
18✔
20
        const idPath = path.get('id');
24✔
21
        
24✔
22
        if (!isBig(idPath))
24✔
23
            return;
24✔
24
        
6✔
25
        push(idPath);
6✔
26
    },
18✔
27
    
18✔
28
    VariableDeclarator(path) {
18✔
29
        let isJSX = false;
42✔
30
        const idPath = path.get('id');
42✔
31
        const initPath = path.get('init');
42✔
32
        
42✔
33
        if (!isBig(idPath))
42✔
34
            return;
42✔
35
        
21✔
36
        path.traverse({
21✔
37
            JSXElement(path) {
21✔
38
                isJSX = true;
3✔
39
                path.stop();
3✔
40
            },
21✔
41
        });
21✔
42
        
21✔
43
        if (isJSX)
21✔
44
            return;
42✔
45
        
18✔
46
        if (initPath.isArrowFunctionExpression())
18✔
47
            return push(idPath);
42✔
48
        
12✔
49
        if (initPath.isFunctionExpression())
12✔
50
            return push(idPath);
42✔
51
    },
18✔
52
});
3✔
53

3✔
54
function toCamel(name) {
60✔
55
    const newName = name.slice(1);
60✔
56
    const [a] = name;
60✔
57
    const b = a.toLowerCase();
60✔
58
    
60✔
59
    return `${b}${newName}`;
60✔
60
}
60✔
61

3✔
62
function isBig({node}) {
93✔
63
    if (!node)
93✔
64
        return false;
93✔
65
    
87✔
66
    if (!node.name)
87✔
67
        return false;
93✔
68
    
84✔
69
    return /[A-Z]/.test(node.name[0]);
84✔
70
}
93✔
71

3✔
72
function checkBig(query, push) {
54✔
73
    return (path) => {
54✔
74
        const keyPath = path.get(query);
27✔
75
        
27✔
76
        if (!isBig(keyPath))
27✔
77
            return;
27✔
78
        
15✔
79
        push(keyPath);
15✔
80
    };
54✔
81
}
54✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc