How to recursively check files with Prettier - prettier

I tried using:
prettier --config .prettierrc.json --check .
and my config is like so:
{
"semi": true
}
and it didn't check subdirectories. How can I tell prettier to do things recursively?
This seems to work:
prettier --config .prettierrc.json --check '**/**'
and so does this:
prettier --config .prettierrc.json --check '**'
but those seem like pretty non-standard commands. What is the canonical way to search recursively?

You should use glob patterns with prettier,
to search recursively you can use ** aka globstar
referencing the Glob documentation
** If a "globstar" is alone in a path portion, then it matches zero or more directories and subdirectories searching for matches. It does not crawl symlinked directories.
referencing the prettier command line interface documentation
prettier --single-quote --trailing-comma es5 --write "{app,__{tests,mocks}__}/**/*.js"
Don't forget the quotes around the globs! The quotes make sure that Prettier expands the globs rather than your shell, for cross-platform usage. The glob syntax from the glob module is used.
Prettier CLI will ignore files located in node_modules directory. To opt-out from this behavior use --with-node-modules flag.

Related

Checking multiple files at one using prettier

I'm trying to run the Prettier CLI tool and what I wanted to do is running it against multiple files at once, is that possible?
I know we can use glob patterns but those files not be easily matched to a pattern. Because I'm trying to run the CLI tool against staged files in a pre-commit hook.
So I was hoping to do something like: prettier --write "file.js, src/file2.js, src/somepath/file2.js"
Is that possible?
You should be able to use curly brackets:
prettier --write "src/file{1,2}.js"
In your example:
prettier --write "{file1,src/file2,src/somepath/file2}.js"
It might be simpler just write out a list of files:
prettier --write -- file1.js src/file2.js src/somepath/file2.js
(-- is explained in https://unix.stackexchange.com/questions/11376/what-does-double-dash-mean-also-known-as-bare-double-dash)

rename regex not working in cygwin

I am using cygwin under windows 7.
In my directory there are files like
fort.100
fort.101
...
fort.1xx
I want to give them all an extension _v1.
When I try to achieve it using rename by
rename 's/$/_v1/' fort.*
the prompt exit with no errors and nothing happens.
I then tried
rename -e 's/$/_v1/' fort.*, an error pops up,
rename: unknown option -- e
I also tried with a different delimiter # instead of / with no luck.
Now, I thought it was due to the character _ in the expression (I am a newbie to regex), I tried escaping it by \_ with no luck either. Again a try without _, for example,
rename 's/$/v11/' fort.* - nothing happens again.
Although I achieved my goal by
for file in fort.*; do mv $file $file\_v1; done, I wonder why rename doesn't work.
What am I doing wrong here? Is it because I am on cygwin?
The manual of rename does not match your expectations.
I see no regex capability.
SYNOPSIS
rename [options] expression replacement file...
DESCRIPTION
rename will rename the specified files by replacing the first occur‐
rence of expression in their name by replacement.
OPTIONS
-v, --verbose
Give visual feedback which files where renamed, if any.
-V, --version
Display version information and exit.
-s, --symlink
Peform rename on symlink target
-h, --help
Display help text and exit.
EXAMPLES
Given the files foo1, ..., foo9, foo10, ..., foo278, the commands
rename foo foo0 foo?
rename foo foo0 foo??
will turn them into foo001, ..., foo009, foo010, ..., foo278. And
rename .htm .html *.htm
will fix the extension of your html files.
for what you want to reach the easy way is:
for i in fort*; do mv ${i} ${i}_v1 ; done
I have found a workaround.
I replaced the util-linux rename to perl rename a separate package.
This was provided from #subogero from GitHub.
All the usual rename expressions is working.

Vim, C++, YCM, and Syntastic include path problems

I feel that I have an awesome setup for C++ programming using Vim but I can't find a way to tell Vim, YCM, and Syntastic where to search for headers. It would be really annoying to have to manually set the include path variables for Vim, YCM, and Syntastic every time I want to work on a project when this information exists in the Makefile. Is there any automated solutions for setting a global include path?
Edit: It won't even find the headers if I set the path like this ":set path = ".,/usr/include,include,../include,/home/steven/ovgl/include,,""
Your headers should appear in your tag files (see :h tags if you don't know about it).
Then YouCompleteMe is able to read the information about your headers from the tag file, as explained in the plugin faq:
YCM does not read identifiers from my tags files
First, put let g:ycm_collect_identifiers_from_tags_files = 1 in your vimrc.
Make sure you are using Exuberant Ctags to produce your tags files since
the only supported tag format is the Exuberant Ctags format. The format
from "plain" ctags is NOT supported. The output of ctags --version should
list "Exuberant Ctags".
Ctags needs to be called with the --fields=+l (that's a lowercase L, not a
one) option because YCM needs the language:<lang> field in the tags
output.
NOTE: Mac OS X comes with "plain" ctags installed by default. brew install
ctags will get you the Exuberant Ctags version.
Also make sure that your Vim tags option is set correctly. See :h 'tags'
for details. If you want to see which tag files YCM will read for a given
buffer, run :echo tagfiles() with the relevant buffer active. Note that
that function will only list tag files that already exist.
You shold look for YCM-Generator. It is a script that generates ycm_extra_conf.py by running make and looking for all flags used. You run it once for project, and rerun only when make file changed.
I had faced a similar issue. I needed this for use with development using llvm.
I solved it by following the below steps:
Ctags -R --fields=+l * in your project/code base.
In your user .vimrc file, add let g:ycm_collect_identifiers_from_tags_files = 1
cp ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py ~/
Add another line in .vimrc let g:ycm_global_ycm_extra_conf = '/home/<user>/ycm_extra_conf.py'
reset terminal or hit bash
Note: You should start vim in the directory with the tags present in it. Or you may need to explicitly specify the directory where the tags are present.

Using two asterisks to add a file in git

I want to add a file which has a unique file name but a long preceding path (e.g. a/b/c/d/filename.java). Normally I would add this to my repository by doing
git add *filename.java.
However I have also done this before:
git add a/b/c/d/filename*
So I tried to combine the two:
git add *filename*
but this does something weird. It adds every untracked file. I can see possible reasons for failure but they all should occur in one of the previous two commands so I don't know why this is happening.
My question isn't so much about how to add a file to a git repository with just its file name (although that would be useful).
My question is what is my misunderstanding of the * operation which makes me think the above should work.
Info:
I am using Git Bash for Windows, which is based on minGW.
You're looking at globs
(not regular expressions, which are a different pattern-matching language), and they're expanded by your shell, not by git.
If you want to see how they're going to match, just pass the same glob to another command, eg.
$ ls -d *filename.java
vs
$ ls -d *filename*
(I've just added the -d so ls doesn't show the contents of any directories that match)
Since you're using git bash, and it's possible that glob expansion behaves differently from a regular shell, try
$ git add --dry-run --verbose -- *filename*
for example: this should show you how it really expands the glob and what effect that has.
Note the -- ... if you're using globs that might match a filename with a leading -, it's important to make sure git knows it's a filename and not an option.
Unfortunately, this will only show you the files which both match the glob, and have some difference between the index and working copy.
Answer from author:
The dry run helped a lot, here is what I found:
I was forgetting about the bin folder which I haven't added, so when I performed the dry run I realised it was finding two matches: filename.java and filename.class. When I changed the glob to *filename.j* it worked.
My next step was to remove the .class and try the command again: it worked! It is still unexplained why git bash added everything when it found two matches... since the dry run behaves differently from the actual run I think there must be a bug, but I think that discussion is to be held elsewhere (unless somebody thinks it isn't a bug).
You could try with git add ./**/*.java
Note: I tested with zsh, it should also work for bash as well.

ignoring folders in mercurial

Caveat:
I try all the posibilities listed here: How can I ignore everything under a folder in Mercurial.
None works as I hope.
I want to ignore every thing under the folder test. But not ignore srcProject\test\TestManager
I try
syntax: glob
test/**
And it ignores test and srcProject\test\TestManager
With:
syntax: regexp
^/test/
It's the same thing.
Also with:
syntax: regexp
test\\*
I have install TortoiseHG 0.4rc2 with Mercurial-626cb86a6523+tortoisehg, Python-2.5.1, PyGTK-2.10.6, GTK-2.10.11 in Windows
Try it without the slash after the caret in the regexp version.
^test/
Here's a test:
~$ mkdir hg-folder-ignore
~$ cd hg-folder-ignore
~/hg-folder-ignore$ echo '^test/' > .hgignore
~/hg-folder-ignore$ hg init
~/hg-folder-ignore$ mkdir test
~/hg-folder-ignore$ touch test/ignoreme
~/hg-folder-ignore$ mkdir -p srcProject/test/TestManager
~/hg-folder-ignore$ touch srcProject/test/TestManager/dont-ignore
~/hg-folder-ignore$ hg stat
? .hgignore
? srcProject/test/TestManager/dont-ignore
Notice that ignoreme isn't showing up and dont-ignore is.
Both cases worked for me (on linux and windows):
syntax: regexp
^backup/ #root folder
nbproject/ #any folder
or
syntax: glob
./backup/* #root folder
nbproject/* #any folder
However, it wasn't before I added a link to .hgignore file to .hgrc file in my repo:
[ui]
ignore = .hg/.hgignore
Also worth mentioning that mercurial ignores files that it is not currently tracking, which are those added before you configured it to ignore them. So, don't be put off by hg status saying some filed are M (modified) or ! (missing) in the folders that you have just added to the ignore list!
You can use zero-width negative look-ahead and look-behind assertions to specify that you want to ignore test only when it's not preceded by srcProject and not followed by TestManager:
syntax: regexp
(?<!srcProject\\)test\\(?!TestManager)
Mercurial uses Python regular expressions, so you can find more info on zero-width assertions in the Python docs: https://docs.python.org/library/re.html#regular-expression-syntax
Create .hgignore file under root directory of the repository
Now add the following contents in the file .
syntax: glob
bin/**
*.DS_Store
This will remove the bin directory and all the *.DS_Store files from the repository