Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should absolute imports come before relative imports?

I'm importing some resources in my Vue file. The fact that it's Vue, though, have nothing to do with my question, I believe.

I import them as such:

import Vue from 'vue'
import { mapState, mapMutations } from 'vuex'
import ChessPiece from '../assets/classes/chesspiece'
import 'vue-awesome/icons/rotate-left'
import 'vue-awesome/icons/search'

ESLint then tells me:

Absolute imports should come before relative imports

I'm just wondering, why is this?

like image 514
Magnus Buvarp Avatar asked Dec 10 '17 01:12

Magnus Buvarp


People also ask

Should I use absolute or relative imports?

Remember that you should generally opt for absolute imports over relative ones, unless the path is complex and would make the statement too long.

What is absolute import and relative import in react?

Using absolute imports to better organize your React project is a great way. Relative imports are hard to follow and break during refactoring. Absolute imports manage your project easier as it grows. Forget long relative imports after this article. This is my 40th Medium article.

How do Python relative imports work?

Relative imports use dot(.) notation to specify a location. A single dot specifies that the module is in the current directory, two dots indicate that the module is in its parent directory of the current location and three dots indicate that it is in the grandparent directory and so on.

Should you use relative imports Python?

Because there, they want to make sure that other developers could also get the full path of the import module. Relative imports are helpful when you are working alone on a Python project, or the module is in the same directory where you are importing the module.


1 Answers

It's just an coding convention to make everything cleaner.

Usually absolute imports comes from external library, and relative imports from your code.

like image 194
Daniel Tran Avatar answered Oct 22 '22 11:10

Daniel Tran