lint

Android Studio's “expected resource of type” checks?

不想你离开。 提交于 2019-11-27 19:02:48
Android Studio Beta (0.8) has a nifty new feature where it checks that some int parameters are not arbitrary integers, but rather have some properties. For example, calling something like: setContentView(R.id.textView1); will correctly report that R.id.textView1 is not a layout id (the message is "expected resource of type layout"). There are other cases of this peppered around. Understandably, this protection is lost as soon as you add your own methods into the mix, e.g. private void mySetContentView(int resourceId) { setContentView(resourceId); } I can then call mySetContentView() with any

One var per function in JavaScript?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 17:23:24
I've been using JSLint to make me feel bad about my JavaScript. It is great, by the way. There is one check that I don't quite understand and I'd like your views, please. From jslint.com : In languages with block scope, it is usually recommended that variables be declared at the site of first use. But because JavaScript does not have block scope, it is wiser to declare all of a function's variables at the top of the function. It is recommended that a single var statement be used per function. What is the last sentance in bold really saying? I think I should be declaring multiple variables like

Proper way to handle Android Studio's NullPointerException lint warning

南笙酒味 提交于 2019-11-27 17:08:42
问题 I'm new to android/java programming and am confused how to properly deal with this warning. Method invocation '' may produce 'Java.lang.NullPointerException' Should I be ussing assert to remove the warning? Or rather a runtime exception? Any help would be appreciated. 回答1: I doubt this question can be answered conclusively, as it's a matter of opinion. Or at least I believe so -- an opinion too. :) I understand you want "0 warnings" (a very laudable goal) but there's probably not a "one size

Turning off eslint rule for a specific file

a 夏天 提交于 2019-11-27 16:53:57
Is it possible to turn off the eslint rule for the whole file? Something such as: // eslint-disable-file no-use-before-define (Analogous to eslint-disable-line.) It happens to me quite often, that in a certain file, I'm breaking a specific rule on many places which is considered OK for that file, but I don't want to disable the rule for the whole project nor do I want to disable other rules for that specific file. You can turn off/change a particular rule for a file by putting the configurations at the top of the file. /* eslint no-use-before-define: 0 */ // --> OFF or /* eslint no-use-before

How to add -Xlint:unchecked to my Android Gradle based project?

拟墨画扇 提交于 2019-11-27 16:50:01
I tried to add the following to the root build.gradle file: subprojects { gradle.projectsEvaluated { tasks.withType(Compile) { options.compilerArgs << "-Xlint:unchecked -Xlint:deprecation" } } } But I'm getting this: FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':Libraries:ActionBarSherlock:compileRelease'. > invalid flag: -Xlint:unchecked -Xlint:deprecation What am I doing wrong? Felipe Lima This is what worked for me: (in your project's build.gradle) allprojects { gradle.projectsEvaluated { tasks.withType(JavaCompile) { options.compilerArgs << "-Xlint

Lint error “Do not treat position as fixed; only use immediately…”

元气小坏坏 提交于 2019-11-27 15:04:15
I'm contributing to open source library and got lint error "Do not treat position as fixed; only use immediately and call holder.getAdapterPosition() to look it up later" for this code: @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { mAdapter.onBindViewHolder(holder, position); if (!isFirstOnly || position > mLastPosition) { for (Animator anim : getAnimators(holder.itemView)) { anim.setDuration(mDuration).start(); anim.setInterpolator(mInterpolator); } mLastPosition = position; } else { ViewHelper.clear(holder.itemView); } } I've checked that it is

JSLint (CLI): options?

只愿长相守 提交于 2019-11-27 14:46:50
问题 I'm running JSLint's Rhino version from the Ubuntu command line like so: $ rhino jslint.js myScript.js While the web interface offers various options, I couldn't figure out how to invoke those via the command line. Am I overlooking anything in the documentation? 回答1: Yes! You did miss it. You can specify the options for jslint at the top of your .js file. See the doc page and read the options section for an example. 回答2: I was inspired by the discussion above, and extended my JSLint wrapper

What exactly does Android's @hide annotation do?

ⅰ亾dé卋堺 提交于 2019-11-27 14:27:46
Lots of internal APIs in Android are marked @hide . What exactly does this do? Another answer says that it only hides the methods from Javadoc, but that you can use reflection to access them. That makes no sense though - if they are only hidden from Javadoc then you surely wouldn't need reflection to access them. In fact I've found that I don't. I can still call some @hide methods (maybe just static ones?) and the app compiles and runs fine as far as I can tell. I just get a lint error: Note that the above code still compiles fine. I don't care about the possibility of the API being changed so

How to configure PyLint to check all things PEP8 checks?

落花浮王杯 提交于 2019-11-27 12:48:58
问题 Searching for an answer on PyLint's mailing list brings no interesting results. PyLint is known to be very customizable so I guess this should be possible... The reason I would like PyLint to check compliance with PEP8 is because PyDev has much better support for PyLint than it has for PEP8. It's easier to have one tool doing all checks than having to use two. I also asked this question on PyLint's mailing list at http://thread.gmane.org/gmane.comp.python.logilab/1039 Example of diagnostic

The result of subscribe is not used

元气小坏坏 提交于 2019-11-27 09:17:54
问题 I've upgraded to Android Studio 3.1 today, which seems to have added a few more lint checks. One of these lint checks is for one-shot RxJava2 subscribe() calls that are not stored in a variable. For example, getting a list of all players from my Room database: Single.just(db) .subscribeOn(Schedulers.io()) .subscribe(db -> db.playerDao().getAll()); Results in a big yellow block and this tooltip: The result of subscribe is not used What is the best practice for one-shot Rx calls like this?