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

Ignore some rules? #802

Closed
Asoul opened this issue Mar 1, 2017 · 11 comments

Comments

@Asoul
Copy link
Contributor

commented Mar 1, 2017

Hi,

I use pg-promise, and some SQL rules looks like:

db.none(
        'UPDATE users SET "Col1" = ${col1}, ' +
        '                 "Col2" = ${col2}, ' +
        '                 "col3" = ${col3}, ' +
        'WHERE col3 = ${col3}', goodTable)

The function need to pass the string with ${}, and I cannot use `` to quote the string, because these variable is not local variables, they are goodTable's attributes. Therefore, I got prefer-template error from this, can I ignore this warning?

Thanks!

@Asoul

This comment has been minimized.

Copy link
Contributor Author

commented Mar 1, 2017

I cannot google some document about these, maybe there is some configuration in package.json?

like

"standard": {
  "ignoreRules": [
    "prefer-template'
  ]
}
@tunnckoCore

This comment has been minimized.

Copy link

commented Mar 1, 2017

Or using eslint ignore comments like eslint-disable-line, eslint-disable, eslint-disable-line rule1, rule2. Both block and single line comments work.

/* eslint-disable prefer-template */

db.none(
        'UPDATE users SET "Col1" = ${col1}, ' +
        '                 "Col2" = ${col2}, ' +
        '                 "col3" = ${col3}, ' +
        'WHERE col3 = ${col3}', goodTable)

/* eslint-enable prefer-template */
@Asoul

This comment has been minimized.

Copy link
Contributor Author

commented Mar 1, 2017

Thanks @tunnckoCore, but that's a lots of lines of these query in my codes,
I think it's a little ugly to add lots of lines of eslint-disable,
Is there another options? thanks

@tunnckoCore

This comment has been minimized.

Copy link

commented Mar 1, 2017

Why lots of lines? If you have more than 2-3-4 rules to ignore for the whole file maybe Standard isn't your thing, don't know. You can define the comment at the top of the file to globally disable these specific rules that you want and it's not needed to re-enable them later.

@Asoul

This comment has been minimized.

Copy link
Contributor Author

commented Mar 1, 2017

Thanks @tunnckoCore, I think I can disable them at the top of file.

@Asoul Asoul closed this Mar 1, 2017

@rstacruz

This comment has been minimized.

Copy link
Member

commented Mar 1, 2017

Might I add it might be a good idea not to ignore standard on this, because this is actually a good candidate for template strings:

import dedent from 'dedent'

db.none(dedent `
  UPDATE users SET
    "Col1" = \${col1},
    "Col2" = \${col2},
    "col3" = \${col3},
    WHERE col3 = \${col3}
`, goodTable)

// dedent is optional, of course
@Asoul

This comment has been minimized.

Copy link
Contributor Author

commented Mar 2, 2017

Thanks @rstacruz, that's more clean and without commented line, I like it

@vitaly-t

This comment has been minimized.

Copy link

commented Mar 2, 2017

Hi guys, I am the author of pg-promise, and just wanted to point out once again at the flexibility of the formatting syntax when it comes to the use of Named Parameters.

If the ES6 template strings is your preferred way to declare queries, then as per the documentation, you can instead use $/propName/ or $[propName] or $<propName> or $(propName).

But the best way to organize all your SQL is via external SQL files, via Query Files, where you can also use ${propName} syntax safely.

Also see pg-promise-demo for a comprehensive example ;)

@Asoul

This comment has been minimized.

Copy link
Contributor Author

commented Mar 2, 2017

Thanks @vitaly-t,
I think I missed lots of good features of pg-promise, I'll check more demos, Thanks!

@nicholaswmin

This comment has been minimized.

Copy link

commented Aug 28, 2017

@rstacruz Unrelated but doesn't your proposed template literal syntax introduce a huge SQL injection risk?

@vitaly-t

This comment has been minimized.

Copy link

commented Aug 28, 2017

@nicholaswmin it doesn't, because all literals are escaped correctly, preventing the injection. For example, every string goes through pgp.as.text for that, and so on, according to the type.

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
5 participants
You can’t perform that action at this time.