Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Personal import sorting style for React (Native) projects

Notifications You must be signed in to change notification settings

ndinata/import-sort-style-rn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Warning

This package has been deprecated in favour of https://github.com/IanVS/prettier-plugin-sort-imports. To achieve a sorting result with that package that is similar-ish to this one, you can use this as reference.

import-sort-style-rn

Sensible import sorting style for React Native projects.

Usage

Installation

yarn add --dev import-sort-cli import-sort-style-rn

Setup

Add the following to your package.json:

"importSort": {
  ".js, .jsx": {
    "parser": "babylon",
    "style": "rn"
  }
}

Typescript

You can use a different parser for Typescript files. More info here.

yarn add --dev import-sort-parser-typescript

Add this to your package.json:

"importSort": {
  ".js, .jsx": {
    "parser": "babylon",
    "style": "rn"
  },
+ ".ts, .tsx": {
+   "parser": "typescript",
+   "style": "rn"
+ }
}

Style

// Modules with side effects (not sorted internally because order may matter)
// React (Native) modules
// Node.js modules
// Installed modules
import 'c';
import 'a';
import React from 'react';
import { Text, ... } from 'react-native';
import { readFile } from 'fs';
import axios from 'axios';

// Absolute project modules
// "External" project modules ("../")
// "Internal" project modules ("./")
import { padding } from 'theme';
import Divider from '../components/Divider';
import Bubble from './Bubble';

References