Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static Module Doesn't Play Nice With ESLint #540

Closed
0xcaff opened this issue Dec 11, 2016 · 5 comments
Closed

Static Module Doesn't Play Nice With ESLint #540

0xcaff opened this issue Dec 11, 2016 · 5 comments

Comments

@0xcaff
Copy link

0xcaff commented Dec 11, 2016

Hello,

When using protobufjs with my react project, I get eslint errors in the file generated using pbjs -t static-module. Here's a gist with my generated file and eslint errors. https://gist.github.com/caffinatedmonkey/918e7fddc80f7c0dc31be0f7fb59966c

The first few errors are caused by the wrapper. It would be nice to have some built-in ones for just commonjs or amd only which also play nice with eslinr under the -t flag.

The ones about reader being undefined seem valid.

Awesome project by the way!

dcodeIO added a commit that referenced this issue Dec 11, 2016
… instead of always using global.root and added additionally necessary eslint comments, see #540
@dcodeIO
Copy link
Member

dcodeIO commented Dec 11, 2016

Refactored this a bit and added a few eslint comments to meet your needs. Try again!

@0xcaff
Copy link
Author

0xcaff commented Dec 11, 2016

Now I get this error:

Error in ./src/proto.js
Module not found: 'protobuf' in /home/drone/go/src/github.com/caffinatedmonkey/dos/frontend/src

 @ ./src/proto.js 8:61-90

It's caused by the wrapper:

(function(global, factory) {
    /* eslint-disable no-undef */

    /* AMD */ if (typeof define === 'function' && define.amd)
        define(["protobuf"], factory); // commenting out this line makes the errors go away.

    /* CommonJS */ else if (typeof require === 'function' && typeof module === 'object' && module && module.exports)
        module.exports = factory(require("protobufjs/runtime"));

    /* eslint-enable no-undef */

@0xcaff
Copy link
Author

0xcaff commented Dec 11, 2016

Also, when fix the wrapper by removing everything except commonjs, I then get a warning about $prototype at:

    /** @alias dos */
    $root.dos = (function() {

        /** @alias dos */
        var dos = {};

        /** @alias dos.DrawMessage */
        dos.DrawMessage = (function() {

            /**
             * Constructs a new DrawMessage.
             * @exports dos.DrawMessage
             * @constructor
             * @param {Object} [properties] Properties to set
             */
            function DrawMessage(properties) {
                if (properties) {
                    var keys = Object.keys(properties);
                    for (var i = 0; i < keys.length; ++i)
                        this[keys[i]] = properties[keys[i]];
                }
            }

            /** @alias dos.DrawMessage.prototype */
            var $prototype = DrawMessage.prototype; // warning unused $prototype

It can be fixed by removing that line or adding the // eslint-disable-next-line no-unused-vars comment to the line above.

dcodeIO added a commit that referenced this issue Dec 11, 2016
dcodeIO added a commit that referenced this issue Dec 11, 2016
@dcodeIO
Copy link
Member

dcodeIO commented Dec 11, 2016

Here you go:

$> pbjs -t static-module -w commonjs ...

@0xcaff
Copy link
Author

0xcaff commented Dec 11, 2016

Thanks! Everything works now! 👍

@0xcaff 0xcaff closed this as completed Dec 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants