UNPKG

canonical

Version:

Canonical code style linter and formatter for JavaScript, SCSS and CSS.

100 lines (99 loc) 15.1 kB
{ "_args": [ [ "eslint-plugin-import@https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-0.12.1.tgz", "/Users/gajus/Documents/dev/canonical-code-style/canonical" ] ], "_from": "eslint-plugin-import@>=0.12.1 <0.13.0", "_id": "eslint-plugin-import@0.12.1", "_inCache": true, "_location": "/eslint-plugin-import", "_phantomChildren": {}, "_requested": { "name": "eslint-plugin-import", "raw": "eslint-plugin-import@https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-0.12.1.tgz", "rawSpec": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-0.12.1.tgz", "scope": null, "spec": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-0.12.1.tgz", "type": "remote" }, "_requiredBy": [ "/eslint-config-canonical" ], "_resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-0.12.1.tgz", "_shasum": "656a9ba6b93ae51ce74c2d3034b6e856afa74475", "_shrinkwrap": null, "_spec": "eslint-plugin-import@https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-0.12.1.tgz", "_where": "/Users/gajus/Documents/dev/canonical-code-style/canonical", "author": { "email": "me@benmosher.com", "name": "Ben Mosher" }, "bugs": { "url": "https://github.com/benmosher/eslint-plugin-import/issues" }, "dependencies": { "babel-runtime": "5.x", "babylon": "^6.1.2", "eslint-import-resolver-node": "^0.1.0" }, "description": "Import with sanity.", "devDependencies": { "babel": "5.x", "babel-eslint": "^4.1.4", "chai": "^3.4.0", "coveralls": "^2.11.4", "eslint": ">=1.8.0", "eslint-import-resolver-node": "file:./resolvers/node", "eslint-import-resolver-webpack": "file:./resolvers/webpack", "istanbul": "^0.4.0", "mocha": "^2.2.1", "redux": "^3.0.4", "remap-istanbul": "^0.5.1" }, "directories": { "test": "tests" }, "greenkeeper": { "ignore": [ "babel", "babel-runtime" ] }, "homepage": "https://github.com/benmosher/eslint-plugin-import", "keywords": [ "es6", "eslint", "eslintplugin", "export", "import", "jsnext", "modules" ], "license": "MIT", "main": "lib/index.js", "name": "eslint-plugin-import", "optionalDependencies": {}, "peerDependencies": { "eslint": ">=1.4.0" }, "readme": "# eslint-plugin-import\n\n[![build status](https://travis-ci.org/benmosher/eslint-plugin-import.svg?branch=master)](https://travis-ci.org/benmosher/eslint-plugin-import)\n[![Coverage Status](https://coveralls.io/repos/benmosher/eslint-plugin-import/badge.svg?branch=master&service=github)](https://coveralls.io/github/benmosher/eslint-plugin-import?branch=coverage)\n[![win32 build status](https://ci.appveyor.com/api/projects/status/3mw2fifalmjlqf56/branch/master?svg=true)](https://ci.appveyor.com/project/benmosher/eslint-plugin-import/branch/master)\n[![npm](https://img.shields.io/npm/v/eslint-plugin-import.svg)](https://www.npmjs.com/package/eslint-plugin-import)\n\nThis plugin intends to support linting of ES2015+ (ES6+) import/export syntax, and prevent issues with misspelling of file paths and import names. All the goodness that the ES2015+ static module syntax intends to provide, marked up in your editor.\n\n**IF YOU ARE USING THIS WITH SUBLIME**: see the [bottom section](#sublimelinter-eslint) for important info.\n\n## Rules\n\n* Ensure imports point to a file/module that can be resolved. ([`no-unresolved`])\n* Ensure named imports correspond to a named export in the remote file. ([`named`])\n* Ensure a default export is present, given a default import. ([`default`])\n* Ensure imported namespaces contain dereferenced properties as they are dereferenced. ([`namespace`])\n* Report any invalid exports, i.e. re-export of the same name ([`export`])\n\n[`no-unresolved`]: ./docs/rules/no-unresolved.md\n[`named`]: ./docs/rules/named.md\n[`default`]: ./docs/rules/default.md\n[`namespace`]: ./docs/rules/namespace.md\n[`export`]: ./docs/rules/export.md\n\nHelpful warnings:\n\n* Report use of exported name as identifier of default export ([`no-named-as-default`])\n\n[`no-named-as-default`]: ./docs/rules/no-named-as-default.md\n\nStyle guide:\n\n* Report CommonJS `require` calls. ([`no-require`])\n* Ensure all imports appear before other statements ([`imports-first`])\n* Report repeated import of the same module in multiple places ([`no-duplicates`])\n\n[`no-require`]: ./docs/rules/no-require.md\n[`imports-first`]: ./docs/rules/imports-first.md\n[`no-duplicates`]: ./docs/rules/no-duplicates.md\n\n## Installation\n\n```sh\nnpm install eslint-plugin-import -g\n```\n\nor if you manage ESLint as a dev dependency:\n\n```sh\n# inside your project's working tree\nnpm install eslint-plugin-import --save-dev\n```\n\nAs of v0.9, all rules are off by default. However, you may configure them manually\nin your `.eslintrc`, or extend one of the canned base configs from the `eslint-config-import`\npackage:\n\n```yaml\n---\nextends:\n - \"eslint:recommended\"\n - import/warnings # after `npm i -D eslint-config-import`-ing\n\n# or configure manually:\nplugins:\n - import\n\nrules:\n import/no-unresolved: [2, {commonjs: true, amd: true}]\n import/named: 2\n import/namespace: 2\n import/default: 2\n import/export: 2\n # etc...\n```\n\n# Resolver plugins\n\nWith the advent of module bundlers and the current state of modules and module\nsyntax specs, it's not always obvious where `import x from 'module'` should look\nto find the file behind `module`.\n\nUp through v0.10ish, this plugin has directly used substack's [`resolve`] plugin,\nwhich implements Node's import behavior. This works pretty well in most cases.\n\nHowever, Webpack allows a number of things in import module source strings that\nNode does not, such as loaders (`import 'file!./whatever'`) and a number of\naliasing schemes, such as [`externals`]: mapping a module id to a global name at\nruntime (allowing some modules to be included more traditionally via script tags).\n\nIn the interest of supporting both of these, v0.11 introduces resolver plugins.\nAt the moment, these are modules exporting a single function:\n\n```js\n\nexports.resolveImport = function (source, file, config) {\n // return source's absolute path given\n // - file: absolute path of importing module\n // - config: optional config provided for this resolver\n\n // return `null` if source is a \"core\" module (i.e. \"fs\", \"crypto\") that\n // can't be found on the filesystem\n}\n```\n\nThe default `node` plugin that uses [`resolve`] is a handful of lines:\n\n```js\nvar resolve = require('resolve')\n , path = require('path')\n , assign = require('object-assign')\n\nexports.resolveImport = function resolveImport(source, file, config) {\n if (resolve.isCore(source)) return null\n\n return resolve.sync(source, opts(path.dirname(file), config))\n}\n\nfunction opts(basedir, config) {\n return assign( {}\n , config\n , { basedir: basedir }\n )\n}\n```\n\nIt essentially just uses the current file to get a reference base directory (`basedir`)\nand then passes through any explicit config from the `.eslintrc`; things like\nnon-standard file extensions, module directories, etc.\n\nCurrently [Node] and [Webpack] resolution have been implemented, but the\nresolvers are just npm packages, so third party packages are supported (and encouraged!).\n\nJust install a resolver as `eslint-import-resolver-foo` and reference it as such:\n\n```yaml\nsettings:\n import/resolver: foo\n```\n\nor with a config object:\n\n```yaml\nsettings:\n import/resolver:\n foo: { someConfigKey: value }\n```\n\n[`resolve`]: https://www.npmjs.com/package/resolve\n[`externals`]: http://webpack.github.io/docs/library-and-externals.html\n\n[Node]: https://www.npmjs.com/package/eslint-import-resolver-node\n[Webpack]: https://www.npmjs.com/package/eslint-import-resolver-webpack\n\n# Settings\n\nYou may set the following settings in your `.eslintrc`:\n\n#### `import/ignore`\n\nA list of regex strings that, if matched by a path, will\nnot report the matching module if no `export`s are found.\nIn practice, this means rules other than `no-unresolved` will not report on any\n`import`s with (absolute) paths matching this pattern, _unless_ `export`s were\nfound when parsing. This allows you to ignore `node_modules` but still properly\nlint packages that define a [`jsnext:main`] in `package.json` (Redux, D3's v4 packages, etc.).\n\n**Note**: setting this explicitly will replace the default of `node_modules`, so you\nmay need to include it in your own list if you still want to ignore it. Example:\n\n```yaml\nsettings:\n import/ignore:\n - node_modules # mostly CommonJS (ignored by default)\n - \\.coffee$ # fraught with parse errors\n```\n\n[`jsnext:main`]: https://github.com/rollup/rollup/wiki/jsnext:main\n\n#### `import/resolver`\n\nSee [resolver plugins](#resolver-plugins).\n\n#### `import/parser`\n\nThis setting allows you to provide a custom parser module, in the event your\nproject uses syntax not understood by Babel.\n\nThis plugin defaults to using Babylon, Babel's internal parser, but is also\ncompatible with Espree's AST. As long as the import nodes follow [ESTree],\nany parser should work.\n\nIf you're using [babel-eslint] as ESLint's parser, and especially if you are using\nany ES7+ features (object spread, decorators, etc.) you should specify it here, as\nwell:\n\n```yaml\nsettings:\n import/parser: babel-eslint\n```\n\nIf you're using the shared config `eslint-config-import`, you can also check out [`import/es7-jsx`],\nwhich enables JSX and all current Babylon ES7 features.\n\nI am hoping to obviate this setting (and `import/parse-options`) entirely via\n[a pull request](https://github.com/eslint/eslint/pull/4649) whereby I can just\nuse whatever parser is configured for ESLint proper. Coming to you whenever\nESLint 2.0 is released. 😎\n\n[custom parser]: https://github.com/eslint/eslint/blob/master/docs/user-guide/configuring.md#specifying-parser\n[babel-eslint]: https://github.com/babel/babel-eslint\n[ESTree]: https://github.com/estree/estree\n\n#### `import/parse-options`\n\nThis setting will be merged 1-level deep (think `Object.assign`) with the default\nparse options and passed as the second parameter to the parser: `parse(file, options)`.\nSee the [`import/es7-jsx`]\nconfig file for an example of explicit parse options for Babylon.\n\nOr, if you are using another parser, you may want to set these options as well.\n(and maybe contribute another config file! i.e. `eslint-config-import/espree`)\n\n[`import/es7-jsx`]: https://github.com/benmosher/eslint-plugin-import/tree/master/config\n\nHere is an example `.eslintrc` for reference:\n\n```yaml\n\nextends:\n - \"eslint:recommended\"\n - import/warnings # optionally start from eslint-config-import\n\n# if not using the `extends` package, make sure to add the plugin here:\nplugins:\n - import\n\nrules:\n import/default: 2\n import/no-unresolved: 1\n\nsettings:\n\n import/ignore:\n # any imported module path matching one of these patterns will not be parsed\n - 'node_modules' # this is the default, but must be included if overwritten\n - '\\\\.es5$'\n\n import/resolver: webpack # will use 'node' if not specified\n\n import/parser: esprima-fb # default is 'babylon'. change if needed.\n```\n\n## SublimeLinter-eslint\n\nSublimeLinter-eslint introduced a change to support `.eslintignore` files\nwhich altered the way file paths are passed to ESLint when linting during editing.\nThis change sends a relative path instead of the absolute path to the file (as ESLint\nnormally provides), which can make it impossible for this plugin to resolve dependencies\non the filesystem.\n\nThis workaround should no longer be necessary with the release of ESLint 2.0, when\n`.eslintignore` will be updated to work more like a `.gitignore`, which should\nsupport proper ignoring of absolute paths via `--stdin-filename`.\n\nIn the meantime, see [roadhump/SublimeLinter-eslint#58](https://github.com/roadhump/SublimeLinter-eslint/issues/58)\nfor more details and discussion, but essentially, you may find you need to add the following\n`SublimeLinter` config to your Sublime project file:\n\n```json\n{\n \"folders\":\n [\n {\n \"path\": \"code\"\n }\n ],\n \"SublimeLinter\":\n {\n \"linters\":\n {\n \"eslint\":\n {\n \"chdir\": \"${project}/code\"\n }\n }\n }\n}\n```\n\nNote that `${project}/code` matches the `code` provided at `folders[0].path`.\n\nThe purpose of the `chdir` setting, in this case, is to set the working directory\nfrom which ESLint is executed to be the same as the directory on which SublimeLinter-eslint\nbases the relative path it provides.\n\nSee the SublimeLinter docs on [`chdir`](http://www.sublimelinter.com/en/latest/linter_settings.html#chdir)\nfor more information, in case this does not work with your project.\n\nIf you are not using `.eslintignore`, or don't have a Sublime project file, you can also\ndo the following via a `.sublimelinterrc` file in some ancestor directory of your\ncode:\n\n```json\n{\n \"linters\": {\n \"eslint\": {\n \"args\": [\"--stdin-filename\", \"@\"]\n }\n }\n}\n```\n\nI also found that I needed to set `rc_search_limit` to `null`, which removes the file\nhierarchy search limit when looking up the directory tree for `.sublimelinterrc`:\n\nIn Package Settings / SublimeLinter / User Settings:\n```json\n{\n \"user\": {\n \"rc_search_limit\": null\n }\n}\n```\n\nI believe this defaults to `3`, so you may not need to alter it depending on your\nproject folder max depth.\n", "readmeFilename": "README.md", "repository": { "type": "git", "url": "git+https://github.com/benmosher/eslint-plugin-import.git" }, "scripts": { "ci-test": "eslint ./src && npm run-script pretest && istanbul cover --report lcovonly --dir reports/coverage _mocha tests/lib/ -- --recursive --reporter dot", "compile": "rm -rf lib/ && babel -d lib/ src/", "cover": "npm run pretest && NODE_PATH=./lib istanbul cover --dir reports/coverage _mocha tests/lib/ -- --recursive --reporter dot; remap-istanbul -i reports/coverage/coverage.json -o reports/coverage/lcov-report --type html", "coveralls": "remap-istanbul -i reports/coverage/coverage.json -o reports/coverage/lcov.info --type lcovonly && cat ./reports/coverage/lcov.info | coveralls", "debug": "NODE_PATH=./lib mocha debug --recursive --reporter dot tests/lib/", "prepublish": "eslint ./src && npm run compile", "pretest": "npm run compile && babel -d tests/lib/ tests/src/", "test": "NODE_PATH=./lib mocha --recursive --reporter dot tests/lib/", "watch": "babel -d lib/ src/ --watch & mocha --recursive --reporter dot --compilers js:babel/register --watch tests/src/" }, "version": "0.12.1" }