react-codemod icon indicating copy to clipboard operation
react-codemod copied to clipboard

create-element-to-jsx: All files being skipped, even though react is included

Open BossGrand opened this issue 9 years ago • 12 comments

not sure why but all my code is being skipped over without explantion

this is how I call the command

jscodeshift -t react-codemod/transforms/create-element-to-jsx.js dealroom/assets/jsx/core/Dialog.js

here is a sample of one of my files that is being skipped

import React from 'react';
import ReactDOM from 'react-dom';

var Dialog = React.createClass({
    
    getInitialState(){

        return {
            show: false,
            onConfirm: null,
            onCancel: null,
            onBackgroundClick: null,
        }

    },

    render(){
        return null;
    },

    showDialogBox(onConfirm, onCancel, onBackgroundClick){
        this.setState({
            show: true,
            onConfirm: onConfirm,
            onCancel: onCancel,
            onBackgroundClick: onBackgroundClick,
        })
    },

    hideDialogBox(){
        this.setState({
            show: false,
            onConfirm: null,
            onCancel: null
        })
    },

    _onConfirm(){
        if(this.state.onConfirm){
            this.state.onConfirm()
            
        }
    },

    _onCancel(){
        if(this.state.onCancel){
            this.state.onCancel()
            
        }
    },
    _onBackgroundClick(){
        if(this.state.onBackgroundClick){
            this.state.onBackgroundClick()
        }
    },


    _renderDialog(){

        const {show} = this.state;
        
        var className = 'toast dialog';
        
        

        var btn1_class = 'btn-primary';
        var btn2_class = 'btn-error';
        if(this.props.reverseBtnColor){
            btn1_class = 'btn-error';
            btn2_class = 'btn-primary';
        }

        ReactDOM.render(
            <div className='toast-container dialog-container'>
                {show?
                    <div>
                        <div className={className}>
                            <div>
                                {this.props.children} 
                            </div>
                            <div className='btns'>
                                <a className={'btn ' + btn1_class} onClick={this._onConfirm}>
                                    {this.props.confirm_text}
                                </a>
                                <a className={'btn ' + btn2_class} onClick={this._onCancel}>
                                    {this.props.cancel_text}
                                </a>
                            </div>
                                
                        </div>
                        <div className='waiting-overlay' onClick={this._onBackgroundClick}/>
                    </div>
                    :null
                }
                
             </div>
        , this.portal)
    },

    componentDidMount(){
        this.portal = document.createElement('toast');
        document.getElementById('portal').appendChild(this.portal);


        this._renderDialog(this.props);
        
    },

    componentWillReceiveProps(new_props){
        this._renderDialog(new_props);
    },
    componentDidUpdate(){
        this._renderDialog(); 
    },

    componentWillUnmount(){
        ReactDOM.unmountComponentAtNode(this.portal);
    }
});

export default Dialog


output

Processing 1 files...
Spawning 1 workers...
Sending 1 files to free worker...
All done.
Results:
0 errors
0 unmodified
1 skipped
0 ok

BossGrand avatar Apr 13 '17 19:04 BossGrand

I'm experiencing the same issue with React-PropTypes-to-prop-types.js

jlmbaka avatar Apr 20 '17 07:04 jlmbaka

@jlmbaka I used the command: jscodeshift --extensions jsx -t react-codemod/transforms/React-PropTypes-to-prop-types.js <dir-path-with-jsx-files>. Successfully transformed all my jsx files. I haven't tested it on js files though.

awdonahue avatar Apr 20 '17 13:04 awdonahue

@BossGrand the create-element-to-jsx script returns null when it doesn't make any changes, which jscodeshift interprets as "skipped" rather than "no change", so I guess it's a minor bug in how that script reports its results. In your case, your file had no usage of React.createElement, so there was nothing to transform. If you throw a React.createElement('div') in your code, you should see that the file gets marked as ok and the code changes to <div>.

Maybe you meant to use a different script? React-PropTypes-to-prop-types and class are the two that have recently received a lot of attention as part of the React 15.5.0 release.

alangpierce avatar Apr 21 '17 01:04 alangpierce

@A-Dubz I've followed your advise and it worked for me, thanks

jlmbaka avatar Apr 24 '17 11:04 jlmbaka

@A-Dubz works for me

Ethaan avatar May 19 '17 23:05 Ethaan

adding --extensions jsx worked for me, why is that not in the documentation??

VictorChen avatar Aug 21 '17 18:08 VictorChen

@VictorChen - https://github.com/reactjs/react-codemod/pull/170

hellatan avatar Aug 24 '17 03:08 hellatan

I ended up doing this manually. So if people think this is fixed or not an issue feel free to close it

BossGrand avatar Nov 03 '17 16:11 BossGrand

is not fixed on windows os ... jscodeshift --extensions jsx -t react-codemod/transforms/create-element-to-jsx.js test.jsx var MyClass = React.createClass({ render() { return <div>123</div> } })

feonit avatar Jun 20 '18 16:06 feonit

This is happening to me on a typescript project with react/sort-comp, using --extensions did not fix it

sarink avatar Apr 19 '19 07:04 sarink

I'm going to close this issue, please file fresh issues with specifics and repros if needed.

threepointone avatar Jul 27 '19 13:07 threepointone

@sarink and @feonit, How did you fix the issue?

ArivAfonso avatar Nov 06 '22 11:11 ArivAfonso