All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.configs.eslint.imports.order.js Maven / Gradle / Ivy

Go to download

A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.

There is a newer version: 4.12.3
Show newest version
const { buildPathGroupsBasedOnWebpackAliases } = require("../helpers");

const pathGroups = buildPathGroupsBasedOnWebpackAliases({});

const pathGroupForKeepingReactImportsAtTop = {
  pattern: "react+(-native|)",
  group: "external",
  position: "before",
};

/*
Example pathGroups structure. Adding this here
so that if anyone wants to add custom config,
they can make use of this:
[
  { pattern: 'apis/**', group: 'internal' },
  { pattern: 'common/**', group: 'internal' },
  { pattern: 'components/**', group: 'internal' },
  { pattern: 'constants/**', group: 'internal' },
  { pattern: 'contexts/**', group: 'internal' },
  { pattern: 'reducers/**', group: 'internal' },
  { pattern: 'Constants', group: 'internal' },
  { pattern: 'neetoui/**', group: 'external' },
  {
    pattern: 'react+(-native|)',
    group: 'external',
    position: 'before'
  }
]
*/
pathGroups.push(pathGroupForKeepingReactImportsAtTop);

module.exports = {
  rules: {
    // auto-fixable: Enforce a convention in module import order - we enforce https://www.bigbinary.com/react-best-practices/sort-import-statements
    "import/order": [
      "error",
      {
        "newlines-between": "always",
        alphabetize: { order: "asc", caseInsensitive: true },
        warnOnUnassignedImports: true,
        groups: [
          "builtin",
          "external",
          "internal",
          "index",
          "sibling",
          "parent",
          "object",
          "type",
        ],
        /*
         * Currently we check for existence of webpack alias
         * config and then iterate over the aliases and create
         * these pathGroups. Only caveat with this mechanism
         * is that in VSCode eslint plugin won't dynamically
         * read it. But eslint cli would!
         */
        pathGroups,
        // Ignore react imports so that they're always ordered to the top of the file.
        pathGroupsExcludedImportTypes: ["react", "react-native"],
      },
    ],
  },
};




© 2015 - 2024 Weber Informatics LLC | Privacy Policy