oppia / oppia-android

A free, online & offline learning platform to make quality education accessible for all.
https://www.oppia.org
Apache License 2.0
298 stars 502 forks source link

Add an XML Linter to the project #970

Open vinitamurthi opened 4 years ago

vinitamurthi commented 4 years ago

Our project has a lot of XML files that describe the look and feel of the application. We would like to add a linter that ensures all the XML files follow the same style. Xmllint seems to be a good fit for us and we would like to use that for our XML files. If you have recommendations for some other linter, please reach out to me to discuss if its a viable option before using it for the project. Steps that need to be completed to add the linter:

NullByte08 commented 4 years ago

@vinitamurthi Can I work on the first task? I was thinking of using lint provided by Android studio itself.

vinitamurthi commented 4 years ago

Sure you can work on this. The Android Studio lint command works for every file right? I am worried that lint would end up affecting our kotlin/protobuf files as well

vinitamurthi commented 4 years ago

Another thing to keep in mind is that we need to run the linter on circleCI as well, which will not have android studio installed. Also avoid using gradle linting because we will be switching to bazel soon

NullByte08 commented 4 years ago

Sure you can work on this. The Android Studio lint command works for every file right? I am worried that lint would end up affecting our kotlin/protobuf files as well

We can manually set up the lint for particular files and exclude other files.

Another thing to keep in mind is that we need to run the linter on circleCI as well, which will not have android studio installed. Also avoid using gradle linting because we will be switching to bazel soon

lint is a standalone tool which can be installed using sdkmanager from command line and run from command line itself without having to install Android Studio or Gradle. But I am not at all familiar with circleCI.

vinitamurthi commented 4 years ago

Sure you can work on this. The Android Studio lint command works for every file right? I am worried that lint would end up affecting our kotlin/protobuf files as well

We can manually set up the lint for particular files and exclude other files.

Another thing to keep in mind is that we need to run the linter on circleCI as well, which will not have android studio installed. Also avoid using gradle linting because we will be switching to bazel soon

lint is a standalone tool which can be installed using sdkmanager from command line and run from command line itself without having to install Android Studio or Gradle. But I am not at all familiar with circleCI.

Okay, let's first verify if it will work as expected for CircleCI as well as on individual machines. One thing to consider is that different people would have different android SDK versions installed so it would be good to verify that the lint tool wouldn't get affected by that. Also, It may be a good idea to look into CircleCI and the configuration we have set up (You can see that here) @BenHenning what do you think about using the Android Studio lint tool for XML linting?

vinitamurthi commented 4 years ago

It would be a good idea to write this down into a small design doc, and we can review it before going forward!

vinitamurthi commented 4 years ago

@NullByte08 Any update on this issue?

NullByte08 commented 4 years ago

@vinitamurthi sorry I was busy in other stuff. If the style guidelines are set then I can run the lint according to that on the codebase and make a pull request to correct the lint errors. Or else, I will check the default lint constraints in android studio and inform you about those. About the circleCI, I have no experience in it so I will read some docs and tutorials and the link you provided to check how we can integrate the Android lint in it. Jenkins has this as a direct plugin but circleCI does not.

I ran the lint before and found these basic errors and warnings and typos:

image

NullByte08 commented 4 years ago

I ran the above only on the layout directory

vinitamurthi commented 4 years ago

Sounds good, if we can run it on CircleCI then I am totally open to using this. As far as the style guide goes, we have a guide written down here. Is that useful?

NullByte08 commented 4 years ago

@vinitamurthi Ok I will work on it and update you on the go.

NullByte08 commented 4 years ago

@vinitamurthi I am unable to take out time to work on the issue so I am currently unassigning myself from this issue. If I get enough time and nobody works on the issue I will work on this issue in the future.

anandwana001 commented 3 years ago

If anyone wants to check on xmllint how does it works:

pre:
    - sudo apt-get install libxml2-utils
anandwana001 commented 3 years ago

Keeping here for reference - https://github.com/alexjlockwood/android-lint-checks-demo

anandwana001 commented 3 years ago

@vinitamurthi Should this issue be blocked on this issue as per the comment - https://github.com/oppia/oppia-android/issues/1742#issue-688440933 ?

vinitamurthi commented 3 years ago

If you mean #1742 be blocked on this issue then yes I think it should be

anandwana001 commented 3 years ago

@vinitamurthi I am thinking opposite here, if we add Android Lint then we can directly use the lint for lining XML files so, in that way, this issue is blocked till the #1742 gets solved correct me if I misunderstood something here!!

BenHenning commented 3 years ago

I believe this is part of our static analyses GSoC project. @anandwana001 can you confirm?

anandwana001 commented 3 years ago

Yes, I guess.

Ensure all XML files follow our XML style guide.

I am bit worry on this here, as this is something which require Bazel support, and not be done using Gradle, is it ok under the project timeline? @BenHenning

BenHenning commented 3 years ago

That's fair @anandwana001. I think the main requirements that need to be met here are:

Am I missing anything?

Correctly formatted example (from home_fragment.xml):

<?xml version="1.0" encoding="utf-8"?>
<layout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto">

  <data>

    <import type="org.oppia.android.R" />

    <variable
      name="viewModel"
      type="org.oppia.android.app.home.HomeViewModel" />
  </data>

  <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:gravity="center">

    <androidx.recyclerview.widget.RecyclerView
      android:id="@+id/home_recycler_view"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:clipToPadding="false"
      android:overScrollMode="never"
      android:paddingTop="36dp"
      android:paddingBottom="148dp"
      android:scrollbars="none"
      app:data="@{viewModel.homeItemViewModelListLiveData}" />

    <View
      android:layout_width="match_parent"
      android:layout_height="6dp"
      android:background="@drawable/toolbar_drop_shadow" />
  </FrameLayout>
</layout>