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

coderaiser / putout / 8393108684

22 Mar 2024 04:04PM CUT coverage: 100.0%. Remained the same
8393108684

push

github

coderaiser
chore: @putout/plugin-nodejs: v11.4.0

8714 of 8714 branches covered (100.0%)

Branch coverage included in aggregate %.

34925 of 34925 relevant lines covered (100.0%)

34628.07 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';
6✔
2

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

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

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

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

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

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

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