ptkdev / eslint-plugin-snakecasejs

:pencil2: ESLint Plugin: enforce snake_case syntax on variables and function names
https://npmjs.com/package/eslint-plugin-snakecasejs
Other
32 stars 4 forks source link

[Feature Request] Get functions/methods from 3rd parties #6

Open levz0r opened 3 years ago

levz0r commented 3 years ago

Versions

Expected Behavior

The plugin should not warn when functions are not snake case in a 3rd party packages.

Actual Behavior

The plugin warns when functions are not snake case in a 3rd party packages.

Steps to Reproduce

  1. Enable plugin
  2. const fs = require("fs");
    fs.readFileSync(...)
      ^
     warning

Screenshots (Optional)

image

ptkdev commented 3 years ago

Use white-list

levz0r commented 3 years ago

Hi,

Thank you for your response. How is it possible to white list all the external functions of all 3rd party packages?

On Sat, Jun 19, 2021, 11:06 Patryk Rzucidło @.***> wrote:

Use white-list https://github.com/ptkdev/eslint-plugin-snakecasejs#-white-list

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ptkdev/eslint-plugin-snakecasejs/issues/6#issuecomment-864373284, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABC2LIR437T24WCXWWGVJKDTTRFWRANCNFSM46W67LPA .

ptkdev commented 3 years ago

Hi @levz0r ! You need read documentation of 3rd party packages, create an array, example ["readFileSync", "exampleFunc", "otherFunc"] and create whitelist in eslint dotfile. You can fork this repo and add this list in plugin.js and send me pull request.

.eslintrc.json

{
    "plugins": [
        "snakecasejs"
    ],
    "settings":
    {
        "snakecasejs/whitelist": ["readFileSync", "exampleFunc", "otherFunc"]
    },
    "rules":
    {
        "snakecasejs/snakecasejs": "error"
    }
}
levz0r commented 3 years ago

So if I get it right then I should add all the functions of all the 3rd parties I'm using in my project? Are you serious?

On Mon, Jun 21, 2021 at 2:53 PM Patryk Rzucidło @.***> wrote:

Hi @levz0r https://github.com/levz0r ! You need read documentation of 3rd party packages, create an array, example ["readFileSync", "exampleFunc", "otherFunc"] and creare whitelist https://github.com/ptkdev/eslint-plugin-snakecasejs#-white-list in eslint dotfile. You can fork this repo and add this list in plugin.js https://github.com/ptkdev/eslint-plugin-snakecasejs/blob/b469a0ed2206a20cb30982d184b247b977af9cba/plugin.js#L52 and send me pull request.

.eslintrc.json

{ "plugins": [ "snakecasejs" ], "settings": { "snakecasejs/whitelist": ["readFileSync", "exampleFunc", "otherFunc"] }, "rules": { "snakecasejs/snakecasejs": "error" } }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ptkdev/eslint-plugin-snakecasejs/issues/6#issuecomment-864971976, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABC2LITRSRNAIR5BOAI4VMDTT4R4TANCNFSM46W67LPA .

ptkdev commented 3 years ago

@levz0r don't exist a way in javascript to get all methods/function from 3rd parties. I write all methods/functions manually in this plugin. If you find way to get v8 methods/functions or get it from 3rd parties you are welcome with PR. If you want add missing methods/functions in plugin.js and send PR you are welcome.

purefan commented 2 years ago

@ptkdev is there a way to namespace the white list? for example, it is ok to ignore fs.readFileSync but if we whitelist readFileSync it applies to every instance of readFileSync, even if for some reason our project makes our own readFileSync function

What information do you get from eslint? is there anything we can use there?

edit: another example is passportjs it has a function serializeUser, but it would be a bad idea to add that to the plugin.js in a pull request

blakerutledge commented 1 year ago

Can't you just exclusively lint the function and variable names that are declared in the user's code?

Right now this is linting everything, even when I do anything like:

import { fileURLToPath } from 'url'

gets linted to:

import { file_u_r_l_to_path } from 'url'

which is clearly broken, as that module does not export a function by that name.

phil294 commented 6 months ago

on top of that, even external_object.externalMethod() gets changed to external_object.external_method() so it's basically not usable :/