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

coderaiser / putout / 7575354030

18 Jan 2024 08:03PM CUT coverage: 100.0%. Remained the same
7575354030

push

github

coderaiser
feature: @putout/engine-reporter: add

8628 of 8628 branches covered (100.0%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 3 files covered. (100.0%)

34722 of 34722 relevant lines covered (100.0%)

17431.36 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
    const camel = toCamel(name);
30✔
10
    
30✔
11
    path.node.name = camel;
30✔
12
    rename(path, name, toCamel(name));
30✔
13
};
3✔
14

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

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

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

3✔
73
function checkBig(query, push) {
54✔
74
    return (path) => {
54✔
75
        const keyPath = path.get(query);
27✔
76
        
27✔
77
        if (!isBig(keyPath))
27✔
78
            return;
27✔
79
        
15✔
80
        push(keyPath);
15✔
81
    };
54✔
82
}
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