Could an prettier plugin enable the ability to set newline count after imports? - eslint

We're using this eslint rule.
import/newline-after-import": ["error", { "count": 2 }]
It puts 2 newlines after imports, but, when using prettier it immediately overrides and sets the newline spacing to 1.
Is this something that could be made configurable with a prettier plugin?

Related

custom 'smartindent' script for vim

I am currently thrown into a new project where the indentation style is a bit special. The basic rule is to use 'keyword+blank' spaces to indent the next line.
For example:
if () {
// indent 3 spaces here
}
while () {
// indent 6 spaces here
}
There are some (or a lot) of exeptions:
else if: use same number of spaces as if (3)
case in switch/case (2 spaces)
...
1) Is there already a plugin available that can do it for me? According to one of the developers this is called 'smart identation'. Unfortunately VIM's smartindent does something different.
2) If the answer to 1 is no. Is there an easy way to configure vim to respect these rules?
I'm not aware of any such plugin, and IMHO this scheme is anything but smart.
However, it is entirely possible to write a custom indent plugin that implements the exact requirements that you have. See :help 'indentexpr'; also, Vim ships with several indent plugins in $VIMRUNTIME/indent/*.vim that can serve as inspiration.
Basically, the algorithm would be like this:
Check the previous line for one of the keywords (if, while, and so on).
If there's a match, calculate the offset and add that to the previous line's indent (indent(v:lnum - 1)); else, use the previous line's indent as is.
If the line contains a }, find the line with the matching {, and use the indent from that line.

Using pre-minimised files

With Brunch is it possible during production build not to minimize certain js files (may be they are already minimised, or else) whilst still packing theses files along with the others ?
Thanks in advance
It certainly is possible. Quoting the docs of uglify-js-brunch,
Joined files can be ignored and be passed-through, using 'ignored' option:
config =
plugins:
uglify:
ignored: /non_minimize\.js/
(https://github.com/brunch/uglify-js-brunch)
The only requirement is that ignored be a regexp, so, for example, if you wanted to ignore several files, e.g. vendor/a.js and vendor/b.js, you'd go about it like this:
ignored: /^venodor\/a\.js|^vendor\/b\.js/
(You have to escape / to treat it as a slash because otherwise it'd be the regexp literal bounds marker, and . to interpret it as a dot and not a placeholder for any one character.)

SublimeText 3 - Nothing works to force indentation to 4 spaces

Issue:
Can't set/change tab indentation in documents
Have tried:
With document open: >Indentation >Tab width: 4
With document open: >Indentation >Convert Indentation to Spaces
Adding the following to user settings:
"smart_indent": true,
"tab_size": 4,
"translate_tabs_to_spaces": true,
"trim_automatic_white_space": true,
"trim_trailing_white_space_on_save": true,
"use_tab_stops": true,
"word_wrap": false
Adding the following to the php-specific preferences:
"tab_size": 4,
"translate_tabs_to_spaces": true
Questions:
Does it seem weird that changing the spaces from the menu doesn't even work? SublimeText states that the tab indentation is 4 spaces - but it's not.
Does anyone know how to force SublimeText to apply a tab indentation to a document or to a project?
Update:
It looks as if ST3 is not recognising some spaces as indentation and thinks they're just spaces - see image
The above image is the result of converting spaces to tabs (the opposite of what I want) to see what ST3 thinks is indentation
Does anyone know how to fix this besides going through every document
and changing spacing on every single line?
The only command from that list that actively changes all indentation in the current file is the > Indentation > Convert Indentation to Spaces. The other settings only take effect from "that point on" (i.e. existing indentation will remain tabs, newly created ones will be spaces). Also, make sure you try running the command after selecting Indentation > Indent using spaces, and Tab Width 4
Could you check that running Convert Indentation to Spaces, and with "draw_white_space": "all", on, that indentation is shown using semi-transparent dots? Navigation with the caret will still "jump" the 4 spaces.
Only other thing I can think of is it's somehow being a read-only file.
Can't comment because I've less than 50 rep.
There is a status bar at the very bottom of the window. If not visible go to View> Show status bar.
At the rightmost end you will see the language of the current file, Here python.
After that, it will show you whether you are using tabs or spaces and how many of them are being used. Click on it and you will get
Taken from https://css-tricks.com/changing-spaces-tabs-sublime-text/

Is it possible to modify the cindent rules for one case in vim?

I am currently using vim as my editor for programming in D. The indent rules are pretty much identical to C, but I've run into a case that vim doesn't handle by default. In D, case statements can take strings which are not properly handled by cindent.
For instance, this works:
switch(blah)
{
case 1:
// something
case some_variable:
// ...
}
But not this:
switch(blah)
{
case "yark":
case "flurb":
// something
case "...":
// ...
}
Is there some way to override that single rule in a custom indent file, or would the entire cindent ruleset have to be reimplemented?
Try Vim 7.3. The indentation rules introduced in this version mainly for JavaScript also fix this particular situation.
With Vim 7.3 the code is correctly indented as:
switch(blah)
{
case "yark":
case "flurb":
// something
case "...":
// ...
}

cindent, smartindent <esc>=% features in vim

I like cindent, smartindent and =% features in vim, which properly indents the code.
But, I have one problem with this, it indents everything with 8 spaces, and if I have few nested ifs, it can be very long line like here, though having so many nested ifs in first place is another question.
4 int main()
5 {
6 if(x)
7 {
8 if(u)
9 {
10 if(y)
11 {
12 }
13 }
14 }
15 }
I tried to set ts=1 and still it doesnt work.
Is there any way to make default indentation level to 4 spaces while using these features?
Edit
set sw=4 solved the problem. No wonder vim always surprises me :)
I believe you're looking for shiftwidth, abbreviated sw.
Edit: a couple quotes from documentation:
shiftwidth: Number of spaces to use for each step of (auto)indent. Used for |'cindent'|, |>>|, |<<|, etc.
tabstop: Number of spaces that a <Tab> in the file counts for.
expandtab: In Insert mode: Use the appropriate number of spaces to insert a <Tab>. Spaces are used in indents with the '>' and '<' commands and when 'autoindent' is on.
smarttab: When on, a <Tab> in front of a line inserts blanks according to 'shiftwidth'. 'tabstop' is used in other places.
Depending on your style, you may have to change more than one of these. Have a look at their help entries if you need more clarification!
Try setting shiftwidth (sw) to 4.
And, if you want to use spaces instead of tabs, set expandtab (et). Then you can change all those tabs to spaces with :retab.

Resources