db-migrate / node-db-migrate

Database migration framework for node
Other
2.32k stars 360 forks source link

Use single quotes in .js files exports._meta.versions #745

Open nodesocket opened 3 years ago

nodesocket commented 3 years ago

I'm submitting a...

Current behavior

The current template for .js files is:

...
exports._meta = {
  "version": 1
};
...

Expected behavior

Can the template for .js files be changed to:

...
exports._meta = {
  'version': 1
};
...

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

I enforce single quotes with my linter jshint and it complains about using double quotes. Plus everywhere else in the file uses single quotes, hopefully double quotes are not required.

Environment


db-migrate version:  0.11.12
db-migrate driver with versions: pg

Additional information:
- Node version: v14.17.5
- Platform:  Mac
flisboac commented 2 years ago

Editing the generated file shouldn't be difficult (e.g. run prettier on the generated file), but I understand where you're coming from.

Although I don't think single quotes are indeed the standard everywhere, I do think some form of project-scoped template selection could be provided by the CLI, when you create a new migration. This way, you could select a template that conforms to your project's standards, and db-migrate just makes sure that the name and location (the date prefix) of the new migration are correct.

It's quite unfortunate that jshint doesn't have a --fix flag, like eslint does. eslint also has a rule for quotes and it is autofixable. If you could migrate to eslint, and while a better option is not provided by db-migrate itself, you could run a command like this to fix your new migrations right after a db-migrate create (also supposing you're using git):

# Path from the root of your project where your migrations are created. Change as needed.
MIGRATIONS_DIR=migrations
git ls-files -o --exclude-standard --full-name | grep "^${MIGRATIONS_DIR}/.*.js" | xargs npx eslint --fix