Stylelint: require tabs instead of spaces for indenting, but don't count tabs - indentation

I frequently nest my CSS code to better understand variations, such as this:
.a .animate {
transition: opacity 0.2s linear;
opacity: 0;
}
html.js .a.show .animate {
opacity: 1;
}
With a rule of "indentation": "tab", Stylelint lists an error with the second definition, expecting zero tabs.
How can I request Stylelint check that tabs are used for indenting (not spaces), but not count them?
Submitted feature request:
https://github.com/stylelint/stylelint/issues/6595

You can write a custom rule as a Stylelint plugin. Custom rules support a particular methodology or toolset, apply to non-standard constructs and features, or be for specific use cases.
However, the Stylelint docs now recommend using a pretty printer, like Prettier, alongside Stylelint for formatting whitespace. Linters and pretty printers are complementary tools that work together to help you write consistent and error-free code.
You can use Stylelint to:
avoid errors
enforce (non-stylistic conventions)
And then use a pretty printer (like Prettier) to format stylistic things like whitespace to an optimal line length.
Prettier is an opinionated formatter, so you may need to relinquish control of how your indent your CSS rules. Alternatively, you can write a Prettier plugin to enforce your specific indentation style.

Related

How can I configure Emacs to highlight C++ that violate a detailed code style?

I've been researching existing C++ code style tools and have yet to find any packages which will allow me to highlight sections of a file which break a detailed code style configuration. While there seem to be several options for basic code style settings (what should/shouldn't be indented, line length > some threshold, etc), other issues do not seem to be addressed. For context, I'm hoping to be able to recognize when I do the following:
{ on same line as function definition (should be next line)
{ on next line after if statement (should be same line)
no space between ) and {
no space between comparisons (should be a == b instead of a== b,a==b, etc)
consecutive new lines
type *var_name or type * var_name instead of type* var_name
and so on...
This style is heavily enforced on my team, and I am having difficulty minimizing inconsistencies. I'm looking for either an existing emacs tool which allow me to customize these settings extensively, or suggestions on how to create an emacs package myself identifies these errors.
As Noufal suggests, Flymake is one option.
Another is Flycheck. I switched from Flymake to Flycheck a few years ago and haven't looked back. Flycheck supports a large number of languages and tools, and seems to require less hand-holding than Flymake.
From its GitHub README:
Features
Supports over 30 programming and markup languages with more than 60 different syntax checking tools
Fully automatic, fail-safe, on-the-fly syntax checking in background
Nice error indication and highlighting
Optional error list popup
Many customization options
A comprehensive manual
A simple interface to define new syntax checkers
A “doesn't get in your way” guarantee
Many 3rd party extensions
For C and C++ code, Flycheck supports Clang and Cppcheck out of the box, and there is a plugin for Google's C++ style guide as well.
And of course you can add your own checkers if you wish.
If you can configure your tool to emit output in the format that can be understood by flymake, it should be able to do it.
Many tools such as gcc itself and others do this so that flymake works.

Autoclose xml tags in C/C++ file in vim

I have some documentation strings embedded within the source code (C/C++ files) as XML tags and I'd like to know what's the most minimal solution to make vim autoclose the tags (closest matching tag).
I've found closetag.vim but is there away to do this neatly without modifying anything but the .vimrc file?
Vim has no built-in support for that, so the closetag.vim plugin is the proper and easiest solution. (I use it myself, too!) Of course, you can develop your own simple mappings (that search backwards for an open tag, get that, drop the attributes, add the slash, and insert that), but:
that will either be very simplistic and therefore often wrong
or ends up with as much complexity as closetag, becoming a reimplementation of that plugin
If some rather strange restrictions (e.g. a custom primitive sync across systems) only allow you to manipulate the ~/.vimrc itself, you could just append the entire plugin's code to it (though I'd recommend against such an ugly hack).

Vim Folding with RainbowParentheses

So, I've looked everywhere for a good rainbow parentheses plugin that will give different level parentheses different colors. I really like the couple that I've found, because they both do a good job of customizability while highlighting the right thing. It supports more than parentheses; chevrons, braces and brackets all get highlighted, which I really like.
It seems like there are quite a few plugins for this!; I'm currently using oblitum's because his is optimized for dark backgrounds (I often work straight from the shell).
So, following the tip at the github for that plugin, I have the "always on" snippet in my .vimrc. But when the always on block is above "syntax enable" it doesn't show {} as being highlighted for cpp files. When the always on block is below syntax enable, folding doesn't work. I think its the nature of the plugin that makes it do this; it goes though the file and adds coloration information. I notice that if I use the command :syntax enable after I've loaded the file when its not recognizing folds, then it does recognize the folds. But at this point, it removes the coloration that rainbow parentheses put on it.
In my .vimrc, I have the follow pertinent lines:
syntax enable
set foldmethod=syntax
set foldenable
set foldlevel=100
let g:rainbow_operators=2
au FileType c,cpp,objc,objcpp call rainbow#activate()
I think that, from looking at syntax files that come with vim, such as c.vim, you can see that certain blocks are annotated as folding. I bet that if you could just write a regex based upon it, you could identify characters as syntactic groups. Then you could just define a colorscheme for it. In fact, the rainbow plugin is actually calling "syn region" commands, so I think that this route is very doable, I'm just not that knowledgable with vim scripting.
Can anybody help me modify possibly the plugin or come up with a script or something that achieves both?
Sorry the lateness, I've tried to solve it at Fix disabled folding (issue #2)
I dimly remember having had the same or a similar problem.
Also XML code highlighting was broken IIRC.
I put 'always on' off, and activated the colored parentheses only when I needed it.
So my working solution was just a shortcut to toggle the plugin on and off.

Is it possible to customize the indent style of XCode?

For example, I'd like to not indent namespaces in C++ code, but the prefpane doesn't seem to have any place to make a decision of this granularity. Is there some hidden config file or something? Or am I just out of luck?
Apple's XCode documentation contains a full list of user preferences, many of them that don't have a corresponding UI. I'm not seeing anything that is namespace-specific however, so I think you might be out of luck.
However, I thought I'd pass along the preferences list in case it's useful.
I've also attempted to do this.
The answer is that whoever did the code formatting in XCode appears to be completely unaware that there are languages other than Objective C, or coding styles other than Apple's.
Here's a list of things that one would want to do that can't be done in XCode.
Indent public: or private: just one space.
Indent namespaces zero spaces.
Alternate indentation for arguments NOT relative to the opening parenthesis.
The last one needs a little discussion. Sometimes, a function or method name can be quite long, as well as its first argument, so you want also to be able to indent like this:
someExcitingClass->AVeryLongMethodNameTraLaLaLaLa(
someLongExpressionOrVariableNameGoesHere,
anotherNameHere);
Of course, you might want to be extracting subexpressions to make the line shorter, but in real-world code this comes up all the time, and creating subexpressions just to fit everything into a reasonable line length is annoying.
It's a terrible shame and I really have no idea what to do. I personally write in emacs and only dip into XCode as a build system but :-D that's not for everyone.
As the Xcode indenter uses just the lexer, and not the AST, you can 'fool' the formatting by defining away the curly braces.
I have:
#define NAMESPACE_OPEN(_name) namespace _name {
#define NAMESPACE_CLOSE(_name) }
#define dsmsg_namespace_open NAMESPACE_OPEN(dsmsg)
#define dsmsg_namespace_close NAMESPACE_CLOSE(dsmsg)
i.e., a generic 'NAMESPACE_OPEN/CLOSE' define, and a define specific to my most-used namespace 'dsmsg'. Then, whenever I want to open the namespace, I use
dsmsg_namespace_open
... code ...
dsmsg_namespace_close
Ugly hack, but I quite like having a specific, named 'close'
I bypass Xcode's indenting altogether, and have a user script that calls uncrustify on the currently displayed document.
#!/bin/sh
#echo -n "%%%{PBXSelection}%%%"
uncrustify -q -c ~/.uncrustify/sample.cfg -l oc+
#echo -n "%%%{PBXSelection}%%%"
Notes:
uncrustify must be in your PATH
you may need to adjust the location of your config file
if you want to have the new code selected in Xcode, uncomment the two echo statements (this can also be used to make a "Format Selection" script, rather than "Format All"
Script Settings:
Input:Entire Document
Directory: Home directory
Output: Replace Document Contents
Errors: display in alert
As of Xcode 4.3.1 no custom namespace indent options are available, however I overcame this irritation by navigating to Preferences->Text Editing->Indentation and disabling "Syntax-aware indenting".
Another possibility is to use Articstic Style (astyle). A tutorial how to integrate astyle into XCode using automator and services can be found here: http://eatmyrandom.blogspot.com/2011/03/xcode-astyle-part-2-for-xcode-4x.html and http://youtu.be/d8bbE6_OHGc

Hide Comments in Code in Unix Environment

I work in a Unix environment with the typical Unix tools (emacs, vim, gvim, sunstudio, etc)
My project has huge gross boilerplate comments on every method. It makes the files thousands of lines long, with a couple hundred lines of actual code. I may be exagerrating a bit but you get the idea. I am looking for a way when viewing these files to hide (not remove) all comments so I can quickly go through the code. C++ comments '//' only.
It all depends on which editor you use. In vim, you can enable folding with :
set foldenable
Then, you'll be able to use different of folding methods, for mainstream languages, you can set :
set foldmethod=syntax
which will enable syntax folding.
There are half a dozen folding methods, I think the best would be to read
help folding
which should answer everything.