In Android Studio, how do I change the Kotlin naming conventions? - android-studio

Android Studio just updated its Kotlin plugin, and suddenly my code is polluted with warnings about the naming conventions. Apparently Google and/or JetBrains think everyone ought to use CamelCase, but (a) I prefer snake_case (use of underscores), (b) nearly every line of my sources now has a lint complaint, making it hard to separate the wheat from the chaff, and (c) I don't have time to rewrite all my code just to pander to other people's aesthetic sense.
How do I convince AS to be a Philistine like me?

In the menu, select File, then Settings. In the leftmost panel of the window that now appears, select Editor, then Inspections. In the next leftmost panel that now appears, find Kotlin, unfold it by clicking on the triangle, then find Naming conventions, and unfold that. You now have two options.
If you want AS to disregard Kotlin naming conventions, you can simply uncheck its box, and the boxes below it.
However, you can actually use this to convince AS to convert to snake_case instead of CamelCase, or any other aesthetic, as opposed to Google's and/or JetBrains'. If you click on, for instance, "Class naming convention," you will see on the right a text box labeled "Pattern:". It will probably contain [A-Z][A-Za-z\d]*. Add an underscore in a strategic location according to regex rules, for instance, [A-Z][_A-Za-z\d]*. Do this for each of the identifier types whose naming convention you'd like to change, and you're good to go.

Related

Search-Everywhere in Android Studio (IntelliJ) makes Search File redundant?

In Android Studio (and IntelliJ), shift-shift is used to Search File (and Everywhere, e.g. class name etc).
I just realize it also have shift-command-O that search for a file.
With shift-shift, it seems to me shift-command-O is redundant.
So I'm checking to see if I have miss something that is in shift-command-O but not in shift-shift?
Shift-Shift shows a popup with occurrences of the string you've entered in names of files, classes, symbols and actions. Shift-Command-O shows a popup with occurrences of the same string only in names of files. Same task, same UI (in recent IJ/AS versions) more narrow filter.
Well you're almost right but there is one main difference in those two commands.
Shift shift will search for a file.
While shift-command-o will go to the specified file.
I guess in a way they to de same, but if you use Shift-command-o you will be redirected to that file and saves you one click.
But feel free to use what you want, shortcuts are for convenience so you should use what is most comfortable.
Here is a link with all shortcuts in IntelliJ IDEA, could be usefull in the future :)
https://resources.jetbrains.com/storage/products/intellij-idea/docs/IntelliJIDEA_ReferenceCard.pdf

Sublime, altering behavior of highlighting definions upon mouse-hover

I have a project with several classes which partly share functions while at other times the functions are different in code, but use the same name.
When hovering over a function name, Sublime highlights every file and line where that definition is found.
In my opinion it would be better if it actually included which class the different highlights belong to.
Is it possible to edit this in some way ?
Assume systems.js contains 4 different classes (1 base, 3 children). I would like to append or prepend the shown strings by the class definition (fetchable via prototype).
The hover popup mentioned in your question is powered by Sublime's internal symbol index, which is created in combination with the syntax definition that's used to syntax highlight files that you're editing. The Sublime syntax system is fairly context free; it parses the structure of the code but it doesn't contain any real structural information about it.
So for example it can determine that getShots is a function or method because of the syntax that was used to define it, but it doesn't know what class it came from.
The code for the hover popup is available in Default/symbol.py (you can use PackageResourceViewer to examine it) and associates symbols under the cursor with other places that it's seen symbols with that name in other files in the project; it literally only knows the information that you see in the popup; places where things by that name are defined and places where things of that name are referenced.
So in one sense, the answer to your question is No; core sublime can't do that because it doesn't have enough code intelligence to be able to figure that sort of thing out; this is exacerbated by dynamic languages like JavaScript where things can theoretically change at runtime as well.
The primary reason for that is because Sublime is extensible enough to support literally every programming language instead of just focusing on one or two (as e.g. PhpStorm does), so it doesn't have the core code to determine the information required.
All that said, since Sublime is indeed extremely extensible, it's possible that external code that does specialize on a language could be leveraged by a package in order to provide the appropriate information.
Two examples of that are SublimeCodeIntel and LSP for example. I don't use either of them myself, so I don't know for sure how good a fit they might be in your workflow.
I highly recommend you shift to Visual Studio Code majorly because sublime is an editor whereas vs code is an IDE. Also, it has very great extension support for all languages. I would recommend you to use jshint which the most popular plugin for js code available for almost all popular editors and IDEs. But still if you want to go with Sublime I suggest you following plugins:
https://www.sitepoint.com/essential-sublime-text-javascript-plugins/

How to highlight variables in sublime?

How to highlight variables in sublime text 3? like in netbeans
Your question is not very clear, but here are some options. First, if you're just trying to get variables highlighted differently, you'll need a color scheme with more options than the default Monokai. There are many available on Package Control, but one in particular that I know will work (since I'm its author) is Neon:
You can use the excellent tmTheme Editor to see how this or hundreds of other themes will look (sort of) in different languages. (I say "sort of" because the highlighting engine used on the website is different than the one in Sublime, so there will be some differences. Overall it's pretty good, though.)
On the other hand, if you're trying to highlight all the instances of the $page variable, you'll have to do two things. First, double-click on $page to select it. Then, select Find -> Quick Find All (or use its keyboard shortcut) to select all the instances of $page in the document:
The gutter icons and colored underlines are from the BracketHighlighter plugin
Unfortunately, this is the only way to get this to work when using PHP and other languages like JavaScript that denote variables with a $ or other symbol. If we were to use Python, for example, you could just double-click on page and it would look like so:
As you can see, all the other instances of page have boxes around them. This behavior is hard-coded into Sublime, so while it can be turned on and off, it can't be modified or told to recognize other characters in any way.
Good luck!

Additional icon to ratchet Ratchicon set

I am using Cordova, Phonegap and Ratchet for an iOS application.
How can I have additional icons with last version of Ratchet?
We tried to use bootstrap icon set but it has some kind of conflict with Ratchet CSS.
I added ratchet-ios7.css from Github, and it seems have more icons but I can not use them and the documentation link of the package is not working too.
Is there any solutions?
I had a similar problem, and managed to fix it as below. BUT, I didn't use this ratchet-ios7.css, and after looking a bit into that, it doesn't look like my answer will apply to that part of your question. This answer is specifically to add icons to the ratchet icons.
So then:
Go to http://icomoon.io/app/
Import the ratchicons.svg (found in the ratchet/ratchicons directory), and import the .svg of the icon set that you want to add to it. (They also have a bunch of their own icon sets as well)
Select any/all of the icons you want included (I suggest at least including all of the ratchicons, just to make sure it doesn't mess up with how the Ratchet stuff works and so you won't have to edit it yourself). When you're satisfied, click the "Font" button at the bottom of the window, and you'll see all the selected icons and their codes (the same ones that can be seen at the bottom of ratchet.css).
In the top left, make sure the "U+" is toggled to true. If it is a darker shade of grey and you see their unicode attributes underneath the icons (ex. "e600"), then it is set to true. I'm not entirely sure what the "fi" toggle does in terms of how it affects the code, but I just left it alone (just to play it safe).
Go through the list and change the names of any icons you want, if they don't accurately convey what they are and/or if they don't conform to the naming convention.
Also in the top-left, click the Preferences button, and in the Font Name input field, replace "icomoon" with "ratchicons". I don't remember if I changed the Class Prefix field or not, though I don't think it particularly matters (someone feel free to correct me on that). Lastly, make sure "Encode & Embed Font in CSS" is checked. Click the "X" button in the top-right.
When everything looks schpick-n-schpam, click the download button in the footer, and you'll get a zip folder.
Unpack that sucker and inside that you will see several folders/files; the one we're looking for is "fonts". Open that one. Inside that you will see 4 files, each one named ratchicons and each with a different file extension (all of which are the ones we need!). Copy all 4 files.
Nagivate to your ratchicons folder (the one you got the initial ratchicons.svg from), and just rename all these to something else (ex. "ratchicons.woff" -> "ratchicons_old.woff"), just to keep the working ones available. Now Paste the new files here.
Now, editing the ratchet.css file directly isn't the best practice, but this doesn't pose any problems as far as I've experienced, so we're going to do just that. Open up ratchet.css and go right to the bottom. You'll see all the .icon- css selectors that come standard with ratchet, and now we're going to add our new ones. Go back to the folder you downloaded and unpacked and open style.css. See all those .icon-*:before{} selectors, like the ones in ratchet.css? Copy all of those, and paste them over the ones in ratchet.css
You should now be able to use your new icons in the exact same way as the standard ratchet icons! Just use the icon's name you gave on the website in the class="" attribute. If you need to change a name or something, just make the edits in the ratchet.css. Also, for anything I missed and/or if you're curious, here's the docs for IcoMoon: http://icomoon.io/#docs
Update
As pointed out in the comments, in the unicode strings, the numbers in the code must be higher than 255. Otherwise, they will conflict with normal ASCII character unicodes. I'm not sure exactly what the lower limit is, but if you stick to much higher numbers (500s-900s) you shouldn't have to worry about it.

List of Resharper Default Formatting and Rules

I'm trying to find a list of all the default formatting and rules that Resharper enforces.
Unfortunately, I'm not having any luck.
We use the tool, but want to provide a document of standards to new hires so they can view the standards prior to coding.
Under the ReSharper menu, then Options, you'll find the current rules and conventions ReSharper is using for this solution. Of particular importance are:
Code Inspection->Inspection Severity: Shows the severity of things that ReSharper detects in code. The more things that are warnings or errors, the more closely you will have to conform code to ReSharper's conventions in order to get the file to "go green", or even to compile. The hierarchy is:
Do Not Show - self-explanatory, ignores the inspection
Hint - Does not show on sidebar, shows as dotted line under code in question. Good example: using "var" when the line of code doesn't otherwise explicitly specify the type being assigned.
Suggestion - Shows on sidebar as green tick, code in question has green underline. Good examples: use of "var" when type is explicitly defined in the assignment, member visibility.
Warning - Shows on sidebar as yellow tick, code in question underlined blue, or text is faded color. Naming convention violations, redundant keywords or qualifiers, unused code members.
Error - Red sidebar tick, code in question either red text or underlined red. By default, nothing that wouldn't cause a compilation error is marked as a ReSharper error, but you can prevent compilation by "promoting" lower-priority inspections to errors.
Languages->Naming Style: This section shows you how ReSharper will expect various types of code member names to be formatted. The "Advanced settings" option also contains the "abbreviations list", which is basically a list of exceptions to the normal camel-casing conventions. By default, all format inconsistencies are warnings, and I do not see a way in 5.1 (the version I use) to change the severity of this.
EDIT: Here's a list of inspections and their default severities for RS 4.5, which is a few versions back but should still have the "meat" of ReSharper's C# inspections. http://unintelligible.org/blog/2010/05/24/resharper-45-inspection-severity-list/
Beyond this, even JetBrains simply refers you to the Options window if you want to see the list of inspections for your current language. So, if you want something more up-to-date, you may have to do it yourself. If you do, be sure to post it somewhere so others don't have to repeat your work.
IMHO company coding standard is more than just formatting. It usually includes project organization conventions, library usage guidelines, etc. Listing every possible formatting rule ReSharper knows about will make it quite long and boring. Few examples for common constructs (which you can copy from bottom part of formatting setup window) should suffice. Providing them with short rationale should not be too hard to do manually.

Resources