Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Im getting the Ktlint error from the Github actions but in Android Studio Ktlint plugin showing no error #444

Closed
hellosagar opened this issue Feb 25, 2021 · 1 comment

Comments

@hellosagar
Copy link

hellosagar commented Feb 25, 2021

This is my file

class AddAssignmentViewModel @ViewModelInject constructor(
    private val databaseRepo: DatabaseRepo,
    private val dataStore: DataStore<Preferences>
) : ViewModel() {
    private var _createAssignment: MutableLiveData<Event<ResponseModel<String>>> = MutableLiveData()
    var createAssignment: LiveData<Event<ResponseModel<String>>> = _createAssignment

    fun createAssignment(
        name: String,
        subject: String,
        branchString: String,
        yearString: String,
        lastSubmissionDateString: String,
        description: String
    ) {
        if (!validateInput(name, subject, branchString, yearString, lastSubmissionDateString, description)) {
            return
        }
        val year = Year.valueOf(yearString)
        val branch = Branch.valueOf(branchString)
        val date = Date()

        viewModelScope.launch {
            val teacherID = getTeacherInfo(dataStore, Constants.TEACHER_ID)

            databaseRepo.createAssignment(
                name, subject, branch, year, date, description, teacherID
            ) { result ->
                _createAssignment.postValue(Event(result))
            }
        }
    }

    private fun validateInput(
        name: String,
        subject: String,
        branchString: String,
        yearString: String,
        lastSubmissionDateString: String,
        description: String
    ): Boolean {

        if (name.isEmpty()) {
            _createAssignment.value = Event(ResponseModel.Error(null, "Name cannot be empty"))
            return false
        }

        if (subject.isEmpty()) {
            _createAssignment.value = Event(ResponseModel.Error(null, "Subject cannot be empty"))
            return false
        }

        if (branchString.isEmpty()) {
            _createAssignment.value = Event(ResponseModel.Error(null, "Branch cannot be empty"))
            return false
        }

        if (yearString.isEmpty()) {
            _createAssignment.value = Event(ResponseModel.Error(null, "Year cannot be empty"))
            return false
        }

        if (lastSubmissionDateString.isEmpty()) {
            _createAssignment.value =
                Event(ResponseModel.Error(null, "Last submission date cannot be empty"))
            return false
        }

        if (description.isEmpty()) {
            _createAssignment.value =
                Event(ResponseModel.Error(null, "Description cannot be empty"))
            return false
        }

        return true
    }
}

Which is showing no error in the Android studio from ktlint plugin but showing an error in the Github actions

Which is this error

File:[./app/src/main/java/dev/sagar/assigmenthub/ui/viewmodel/AddAssignmentViewModel.kt]
ERROR! Found errors in [ktlint] linter!
ERROR:[/github/workspace/app/src/main/java/dev/sagar/assigmenthub/ui/viewmodel/AddAssignmentViewModel.kt:36:1: Unexpected indentation (16) (should be 12)
/github/workspace/app/src/main/java/dev/sagar/assigmenthub/ui/viewmodel/AddAssignmentViewModel.kt:37:1: Unexpected indentation (16) (should be 12)
/github/workspace/app/src/main/java/dev/sagar/assigmenthub/ui/viewmodel/AddAssignmentViewModel.kt:38:1: Unexpected indentation (16) (should be 12)
/github/workspace/app/src/main/java/dev/sagar/assigmenthub/ui/viewmodel/AddAssignmentViewModel.kt:39:1: Unexpected indentation (16) (should be 12)
/github/workspace/app/src/main/java/dev/sagar/assigmenthub/ui/viewmodel/AddAssignmentViewModel.kt:40:1: Unexpected indentation (16) (should be 12)
/github/workspace/app/src/main/java/dev/sagar/assigmenthub/ui/viewmodel/AddAssignmentViewModel.kt:41:1: Unexpected indentation (16) (should be 12)
/github/workspace/app/src/main/java/dev/sagar/assigmenthub/ui/viewmodel/AddAssignmentViewModel.kt:42:1: Unexpected indentation (12) (should be 8)]
---------------------------
@Tapchicoma
Copy link
Collaborator

This plugin only intended to be used via Gradle task. It's integration with Android Studio (or IDEA) is rudimentary, because of KtLint project itself. This issue tries to address it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants