schuchard / prettier-schematic Goto Github PK
View Code? Open in Web Editor NEWAdd Prettier to an Angular project
License: MIT License
Add Prettier to an Angular project
License: MIT License
Describe the bug
Received the error bellow after attempting to add through the command ng g @schuchard/prettier:add
Error:
Expected end of file, got ", { "extends": [ ..." at 108:1.
To Reproduce
Steps to reproduce the behavior:
npm install -g @schuchard/prettier
ng g @schuchard/prettier:add
Expected behavior
Process to complete without errors and the creation of prettier and tslint config files.
Desktop
Angular CLI: 7.0.2
Node: 9.11.1
OS: darwin x64
Angular:
...
@angular-devkit/architect 0.10.2
@angular-devkit/core 7.0.2
@angular-devkit/schematics 7.0.2
@schematics/angular 7.0.2
@schematics/update 0.10.2
rxjs 6.3.3
typescript 3.1.3
Describe the bug
After upgrading my Ionic Angular project from 9 to 11 and replacing tslint with eslint I get a Windows Script Host error.
To Reproduce
Upgrade an existing Angular project from version 9 to 11 and replace tslint with eslint
Expected behavior
I don't expect that windows outputs an error.
Desktop (please complete the following information):
Additional context
It seems like the real error is that the index.js file doesn't get executed by node?
Describe the bug
The bug manifests when @schuchard/prettier
is installed after prettier. In my scenario, I was doing it through npm ci
on a build machine, but you can run npm i prettier && npm i @schuchard/prettier
to replicate it.
The output is:
$ npx prettier --write "**/*.{js,json,css,md,ts,html,component.html}"
/source/test/node_modules/.bin/prettier: line 1: use strict: command not found
/source/test/node_modules/.bin/prettier: line 2: syntax error near unexpected token `exports,'
/source/test/node_modules/.bin/prettier: line 2: `Object.defineProperty(exports, "__esModule", { value: true });'
To Reproduce
Steps to reproduce the behavior:
npm i prettier && npm i @schuchard/prettier
npx prettier --write "**/*.{js,json,css,md,ts,html,component.html}"
Expected behavior
Prettier runs as expected
Desktop (please complete the following information):
Additional context
From my investigation, it appears that this library is overwriting the symlink for prettier in node_modules/.bin/prettier
.
By doing an ls -ahl node_modules/.bin/prettier
you can see where the symlinks point.
After prettier
is installed: prettier -> ../prettier/bin-prettier.js
after
After @schuchard/prettier
is installed: prettier -> ../@schuchard/prettier/src/prettier/index.js
Now I'm not sure what the actual bug is. Whether it is that the prettier symlink is being overwritten, or that the script file that it is linking to doesn't have the proper #!/usr/bin/env node
as the npm bin docs says to do.
My intuition is that the prettier library bin symlink shouldn't be overwritten.
Describe the bug
In the current configuration, the pre-commit hook doesn't work if version 5 or above of husky is installed
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Prettier should add an empty line to the end of the scss file
Actual
Prettier does not run.
Screenshots
If applicable, add screenshots to help explain your problem.
Was able to fix by installing husky@4 (installed v4.3.8)
Is your feature request related to a problem? Please describe.
lint-staged
since v10 doesn't recommend to use git add
accordingly to https://github.com/okonet/lint-staged/releases/tag/v10.0.0 (BREAKING CHANGES) because now they do it internally.
Describe the solution you'd like
So if I understand correctly the lint-staged
configuration can be simplified via removing git add
.
Is your feature request related to a problem? Please describe.
Run prettier check automatically during ng lint
Describe the solution you'd like
I think that a CLI builder can be setup to run prettier check on ng lint
https://angular.io/guide/cli-builder
angularfire does something similar with ng deploy
https://github.com/angular/angularfire
Describe alternatives you've considered
An alternative would be to modify package.json
so that lint
is ng lint && npm run prettier
.
Is there a reason to use prettier.config.js over json format?
I wonder if I can change it to json format.
Thanks
When I run the command npm run prettier
or try to commit, this error happens. What could be wrong?
prettier --write found some errors. Please fix them and try committing again.
/../node_modules/.bin/prettier: linha 1: use strict: command not found
/../node_modules/.bin/prettier: linha 2: syntax error next to unexpected token `exports,'
/../node_modules/.bin/prettier: linha 2: `Object.defineProperty(exports, "__esModule", { value: true });'
husky > pre-commit hook failed (add --no-verify to bypass)
Log File:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'prettier' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prettier' ]
5 info lifecycle projectX~prettier: projectX
6 verbose lifecycle projectX~prettier: unsafe-perm in lifecycle true
7 verbose lifecycle projectX~prettier: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/opt/desenvolvimento/Trabalho/Pontta/projectX/node_modules/.bin:/home/arch/.yarn/bin:/home/arch/.config/yarn/global/node_modules/.bin:/home/arch/.npm-global/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
8 verbose lifecycle projectX~prettier: CWD: /opt/desenvolvimento/Trabalho/Pontta/projectX
9 silly lifecycle projectX~prettier: Args: [ '-c',
9 silly lifecycle 'prettier --write "**/*.{js,json,css,md,ts,html,component.html}"' ]
10 silly lifecycle projectX~prettier: Returned: code: 2 signal: null
11 info lifecycle projectX~prettier: Failed to exec prettier script
12 verbose stack Error: projectX prettier: `prettier --write "**/*.{js,json,css,md,ts,html,component.html}"`
12 verbose stack Exit status 2
12 verbose stack at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
12 verbose stack at EventEmitter.emit (events.js:182:13)
12 verbose stack at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
12 verbose stack at ChildProcess.emit (events.js:182:13)
12 verbose stack at maybeClose (internal/child_process.js:978:16)
12 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
13 verbose pkgid projectX
14 verbose cwd /opt/desenvolvimento/Trabalho/Pontta/projectX
15 verbose Linux 4.19.2-arch1-1-ARCH
16 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "prettier"
17 verbose node v11.2.0
18 verbose npm v6.4.1
19 error code ELIFECYCLE
20 error errno 2
21 error projectX prettier: `prettier --write "**/*.{js,json,css,md,ts,html,component.html}"`
21 error Exit status 2
22 error Failed at the projectX prettier script.
22 error This is probably not a problem with npm. There is likely additional logging output above.
23 verbose exit [ 2, true ]
My prettier.config
file
module.exports = {
printWidth: 80,
tabWidth: 2,
useTabs: true,
semi: false,
singleQuote: true,
trailingComma: 'none',
bracketSpacing: true,
jsxBracketSameLine: false,
arrowParens: 'avoid',
rangeStart: 0,
rangeEnd: Infinity,
parser: 'angular',
requirePragma: false,
insertPragma: false,
proseWrap: 'always'
};
Describe the bug
In have installed the schematic and added script: npm run prettier
script to my Azure Pipeline.
It runs prettier -c \"**/*.{js,json,css,scss,less,md,ts,html,component.html}\"
as configuring in package.json scripts.
This will call node_modules/.bin/prettier which is a symlink to index.js of this package.
The error in the pipeline I get is:
/home/vsts/work/1/s/src/node_modules/.bin/prettier: 1: use strict: not found
/home/vsts/work/1/s/src/node_modules/.bin/prettier: 2: Syntax error: word unexpected (expecting ")")
It seems that it is trying to execute the Node script as bash.
I can reproduce it by running npm ci
locally and then npm run prettier
.
When I add this to index.js:1 manually, everything works:
#!/usr/bin/env node
Can you reproduce this? If this is really a bug, the above solution might work for everyone.
Describe the bug
css
file suffix only is mentioned in the prettier npm script
To Reproduce
Steps to reproduce the behaviour:
package.json
prettier
script`Expected behaviour
It should detect what is the project style preprocessor and use its file suffix along with CSS
Desktop (please complete the following information):
Additional question:
Why is there component.html
alongside with html
? It does not seem to have any additional effect.
When I stage my changes and run commit --amend, prettier --write is running, while running it getting failed
Node version 14 and npm 6 version i have
Describe the bug
When I run the prettier NPM script, the command never runs. Instead, it takes me to index.js file inside node_modules@schuchard\prettier\src\prettier. VS Code editor stops on line 19 of that file.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Expected all of the files inside my project to get pretty. :)
Screenshots
Here's a screenshot of where my editor takes me soon after running the command.
Desktop (please complete the following information):
Angular CLI: 7.3.5
Node: 10.13.0
OS: win32 x64
Angular: 7.2.9
Additional context
I removed @schuchard/prettier package from my dev dependencies in package.json file, while leaving the other packages that came from schematic intact, reinstalled prettier, and the NPM command worked. Strange...
I cannot build our angular project due to a clash of types between jasmine and jest. Jasmine is added as a dependency and therefore installed when the package is installed. Jasmine should be installed as a devdep rather than a dep.
Describe the solution you'd like
Add option to use https://github.com/simonhaenisch/prettier-plugin-organize-imports#readme
Not sure if this is the right forum, but I'd like to hear people's experience using Prettier in an Angular project. I'm hesitant to use it because of this issue: How can I prevent prettier from taking multi-line array to a single line? #352.
Describe the bug
angular/components#21045
To Reproduce
Steps to reproduce the behavior:
ng update @angular/core @angular/cli @angular/material
in a project on Angular v10 to update to v11Expected behavior
No exceptions.
Screenshots
N/A
Desktop (please complete the following information):
Additional context
The deprecated Workspace APIs were removed in v11. It looks like these schematics need some updates to the newest CLI DevKit.
Describe the bug
When airbnb rules are used, and tslint.json is simplified to:
{ "extends": "tslint-config-airbnb", "rulesDirectory": ["node_modules/codelyzer"] }
then ng g @schuchard/prettier:add
commands shows “Cannot convert undefined or null to object” error after answering all questions.
To Reproduce
Steps to reproduce the behavior:
npm install @schuchard/prettier@latest --save-dev
npx ng g @schuchard/prettier:add
and answer all questions.Expected behavior
No error, tslint.json updated if necessary.
Desktop (please complete the following information):
Describe the bug
Hi, from a time to here @angular/cli adds to tslint.json "tslint: recommended", because of this all the rules are not deleted.
To Reproduce
Create a new angular app with @angular/cli
Expected behavior
Maybe add tslint-config-prettier?
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.