Giter VIP home page Giter VIP logo

pg-formatter's Issues

update to 4.4?

Currently, pg_format 4.1 seems to be bundled. could you update it to current?

Locale issues on Windows

I'm using the Strawberry Perl distro on Windows, along with Node 20.10.0. When I invoke pg-formatter out of the box, it does what it's supposed to, but then it also outputs:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LC_ALL = "C.UTF-8",
        (possibly more locale environment variables)
        LANG = (unset)
    are supported and installed on your system.
perl: warning: Falling back to the system default locale ("English_United States.1252").

I'm a newbie with Perl and haven't been able to find much info about locale handling on Windows. But after a lot of poking around, I tracked this down to:

pg-formatter/src/format.ts

Lines 121 to 123 in 6e1c8af

env: {
LC_ALL: 'C.UTF-8',
},

If I change the value of LC_ALL to C on line 122, then everything works fine with no warnings. (It also works if I remove lines 121-123 entirely.)

Is using C an appropriate fix on Windows? Or is there a better approach? In either case, can this be built into pg-formatter by checking process.platform?

Crashes (and potential code injection) if pwd contains spaces or special characters

https://github.com/gajus/pg-formatter/blob/master/src/format.js#L112 runs perl with an executablePath which is not properly quoted. If the working-directory name contains spaces or other special characters, they will be interpreted as shell syntax. In the normal case, someone made the mistake of checking out their project to a directory with spaces in a parent path, and this winds up crashing. (This happened to another developer on my team). In the worst case, admittedly an unlikely case given how this library would normally be used but definitely not impossible, this is running in a context where the parent path has an attacker-controlled directory name in it, and this injects arbitrary shell or perl code.

Reading configuration from rcfile (`.pg_format`)

Greetings @gajus !

Thank you for a great package, I started using it in one of my projects, it is quite handy.

I am wondering if reading config from .pg_format works, can't find the logic for it after briefly skimming the code.

So, what I was trying to do - adding a small config, like this:

no-extra-line=1

running pg_format with this config works, but pg-formatter seems to ignore it.

I also did not find -L | --no-extra-line param in CLI here.
I am happy to provide a patch to add this one, if that'd be the way to go.

Best,
Rust

[Idea] Prettier plugin

Hey @gajus ,

did you already consider putting this into a prettier plugin?

I really like your eslint plugin which provides formatting as an auto-fix (via this lib) for tagged template literals. However, for normal .sql a different solution is needed (e.g. calling the CLI manually).
Since there are pretty decent prettier integrations for most IDEs, it would be nice to have this as a prettier plugin.

I started using a very simple custom plugin like the following in my private projects:

Code (simple prettier plugin)
const format = require('pg-formatter').format;

// see: https://github.com/gajus/pg-formatter#configuration
const FORMAT_OPTIONS = {
functionCase: 'uppercase',
keywordCase: 'uppercase',
spaces: 2,
};

const languages = [
{
  name: 'SQL',
  parsers: ['postgresql'],
  extensions: ['.pgsql', '.sql'],
},
];

const parsers = {
postgresql: {
  parse: sql => ({ sql }),
  astFormat: 'postgresql',
},
};

const printers = {
postgresql: {
  print(path) {
    const sql = path.getValue().sql;
    return format(sql, FORMAT_OPTIONS);
  },
},
};

module.exports = {
languages,
parsers,
printers,
};

Maybe we can add a prettier plugin to format not only .sql files but tagged template literals as well?
The prettier API is somewhat limited (e.g. see prettier/prettier#12139 ) but I was thinking of overwriting the typescript/javascript parser and adding the formatter as post-processing plugin to the AST output. However, this is just a very rough idea and I have no PoC yet.

CLI interface broken - node execution context missing

Hey. Handy wrapper 👍.

For me (v2.0.2) the CLI interface cannot be called directly:

❯ npm install pg-formatter -g
❯ pg-formatter --help
/opt/homebrew/bin/pg-formatter: line 1: use strict: command not found
/opt/homebrew/bin/pg-formatter: line 2: syntax error near unexpected token `('
/opt/homebrew/bin/pg-formatter: line 2: `var __importDefault = (this && this.__importDefault) || function (mod) {'

Same for installing this as devDependency and trying to call it via npx pg-formatter

Workaround for now is: ❯ node node_modules/.bin/pg-formatter

The dist file is missing: #!/usr/bin/env node at the top

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.