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

Add URL to rule documentation to the metadata #998

Merged
merged 6 commits into from
Jan 9, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/docsUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const repoUrl = 'https://github.com/benmosher/eslint-plugin-import'

export default function docsUrl(ruleName, commitHash) {
let baseUrl = `${repoUrl}/tree/master/docs/rules`
Copy link
Contributor

@j-f1 j-f1 Jan 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be blob/master, too. tree is used for directories, while blob is used for files.

Copy link
Contributor Author

@Arcanemagus Arcanemagus Jan 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, it looks like this is a pretty common mistake since GitHub automatically redirects the wrong link, but you are absolutely correct.

if (commitHash) {
baseUrl = `${repoUrl}/blob/${commitHash}/docs/rules`
}

return `${baseUrl}/${ruleName}.md`
}
5 changes: 4 additions & 1 deletion src/rules/default.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import Exports from '../ExportMap'
import docsUrl from '../docsUrl'

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('default'),
},
},

create: function (context) {
Expand Down
5 changes: 4 additions & 1 deletion src/rules/export.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import ExportMap, { recursivePatternCapture } from '../ExportMap'
import docsUrl from '../docsUrl'

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('export'),
},
},

create: function (context) {
Expand Down
8 changes: 8 additions & 0 deletions src/rules/exports-last.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import docsUrl from '../docsUrl'

function isNonExportStatement({ type }) {
return type !== 'ExportDefaultDeclaration' &&
type !== 'ExportNamedDeclaration' &&
type !== 'ExportAllDeclaration'
}

module.exports = {
meta: {
docs: {
url: docsUrl('exports-last'),
},
},

create: function (context) {
return {
Program: function ({ body }) {
Expand Down
13 changes: 8 additions & 5 deletions src/rules/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path'

import resolve from 'eslint-module-utils/resolve'
import { isBuiltIn, isExternalModuleMain, isScopedMain } from '../core/importType'
import docsUrl from '../docsUrl'

const enumValues = { enum: [ 'always', 'ignorePackages', 'never' ] }
const patternProperties = {
Expand All @@ -10,7 +11,7 @@ const patternProperties = {
}
const properties = {
type: 'object',
properties: {
properties: {
'pattern': patternProperties,
'ignorePackages': { type: 'boolean' },
},
Expand Down Expand Up @@ -46,15 +47,17 @@ function buildProperties(context) {
// If ignorePackages is provided, transfer it to result
if (obj.ignorePackages !== undefined) {
result.ignorePackages = obj.ignorePackages
}
}
})

return result
}

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('extensions'),
},

schema: {
anyOf: [
Expand All @@ -66,7 +69,7 @@ module.exports = {
{
type: 'array',
items: [
enumValues,
enumValues,
properties,
],
additionalItems: false,
Expand All @@ -75,7 +78,7 @@ module.exports = {
type: 'array',
items: [properties],
additionalItems: false,
},
},
{
type: 'array',
items: [patternProperties],
Expand Down
6 changes: 5 additions & 1 deletion src/rules/first.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import docsUrl from '../docsUrl'

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('first'),
},
},

create: function (context) {
Expand Down
8 changes: 7 additions & 1 deletion src/rules/group-exports.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
const meta = {}
import docsUrl from '../docsUrl'

const meta = {
docs: {
url: docsUrl('group-exports'),
},
}
/* eslint-disable max-len */
const errors = {
ExportNamedDeclaration: 'Multiple named export declarations; consolidate all named exports into a single export declaration',
Expand Down
11 changes: 9 additions & 2 deletions src/rules/imports-first.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import first from './first'
import docsUrl from '../docsUrl'

const newMeta = Object.assign({}, first.meta, { deprecated: true })
const first = require('./first')

const newMeta = Object.assign({}, first.meta, {
deprecated: true,
docs: {
url: docsUrl('imports-first', '7b25c1cb95ee18acc1531002fd343e1e6031f9ed'),
},
})

module.exports = Object.assign({}, first, { meta: newMeta })
5 changes: 4 additions & 1 deletion src/rules/max-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import isStaticRequire from '../core/staticRequire'
import docsUrl from '../docsUrl'

const DEFAULT_MAX = 10

Expand All @@ -15,7 +16,9 @@ const countDependencies = (dependencies, lastNode, context) => {

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('max-dependencies'),
},

schema: [
{
Expand Down
5 changes: 4 additions & 1 deletion src/rules/named.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import * as path from 'path'
import Exports from '../ExportMap'
import docsUrl from '../docsUrl'

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('named'),
},
},

create: function (context) {
Expand Down
7 changes: 6 additions & 1 deletion src/rules/namespace.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import declaredScope from 'eslint-module-utils/declaredScope'
import Exports from '../ExportMap'
import importDeclaration from '../importDeclaration'
import declaredScope from 'eslint-module-utils/declaredScope'
import docsUrl from '../docsUrl'

module.exports = {
meta: {
docs: {
url: docsUrl('namespace'),
},

schema: [
{
'type': 'object',
Expand Down
5 changes: 4 additions & 1 deletion src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import isStaticRequire from '../core/staticRequire'
import docsUrl from '../docsUrl'

import debug from 'debug'
const log = debug('eslint-plugin-import:rules:newline-after-import')
Expand Down Expand Up @@ -44,7 +45,9 @@ function isClassWithDecorator(node) {

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('newline-after-import'),
},
schema: [
{
'type': 'object',
Expand Down
7 changes: 5 additions & 2 deletions src/rules/no-absolute-path.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { isAbsolute } from '../core/importType'
import moduleVisitor, { makeOptionsSchema } from 'eslint-module-utils/moduleVisitor'
import { isAbsolute } from '../core/importType'
import docsUrl from '../docsUrl'

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('no-absolute-path'),
},
schema: [ makeOptionsSchema() ],
},

Expand Down
6 changes: 5 additions & 1 deletion src/rules/no-amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
* @author Jamund Ferguson
*/

import docsUrl from '../docsUrl'

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('no-amd'),
},
},

create: function (context) {
Expand Down
6 changes: 6 additions & 0 deletions src/rules/no-anonymous-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* @author Duncan Beevers
*/

import docsUrl from '../docsUrl'

const defs = {
ArrayExpression: {
option: 'allowArray',
Expand Down Expand Up @@ -69,6 +71,10 @@ const defaults = Object.keys(defs)

module.exports = {
meta: {
docs: {
url: docsUrl('no-anonymous-default-export'),
},

schema: [
{
type: 'object',
Expand Down
6 changes: 5 additions & 1 deletion src/rules/no-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* @author Jamund Ferguson
*/

import docsUrl from '../docsUrl'

const EXPORT_MESSAGE = 'Expected "export" or "export default"'
, IMPORT_MESSAGE = 'Expected "import" instead of "require()"'

Expand All @@ -19,7 +21,9 @@ function allowPrimitive(node, context) {

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('no-commonjs'),
},
},

create: function (context) {
Expand Down
7 changes: 5 additions & 2 deletions src/rules/no-deprecated.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Exports from '../ExportMap'
import declaredScope from 'eslint-module-utils/declaredScope'
import Exports from '../ExportMap'
import docsUrl from '../docsUrl'

function message(deprecation) {
return 'Deprecated' + (deprecation.description ? ': ' + deprecation.description : '.')
Expand All @@ -16,7 +17,9 @@ function getDeprecation(metadata) {

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('no-deprecated'),
},
},

create: function (context) {
Expand Down
5 changes: 4 additions & 1 deletion src/rules/no-duplicates.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import resolve from 'eslint-module-utils/resolve'
import docsUrl from '../docsUrl'

function checkImports(imported, context) {
for (let [module, nodes] of imported.entries()) {
Expand All @@ -12,7 +13,9 @@ function checkImports(imported, context) {

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('no-duplicates'),
},
},

create: function (context) {
Expand Down
6 changes: 5 additions & 1 deletion src/rules/no-dynamic-require.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import docsUrl from '../docsUrl'

function isRequire(node) {
return node &&
node.callee &&
Expand All @@ -13,7 +15,9 @@ function isStaticValue(arg) {

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('no-dynamic-require'),
},
},

create: function (context) {
Expand Down
5 changes: 4 additions & 1 deletion src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import minimatch from 'minimatch'
import resolve from 'eslint-module-utils/resolve'
import importType from '../core/importType'
import isStaticRequire from '../core/staticRequire'
import docsUrl from '../docsUrl'

function getDependencies(context, packageDir) {
try {
Expand Down Expand Up @@ -112,7 +113,9 @@ function testConfig(config, filename) {

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('no-extraneous-dependencies'),
},

schema: [
{
Expand Down
5 changes: 4 additions & 1 deletion src/rules/no-internal-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import minimatch from 'minimatch'
import resolve from 'eslint-module-utils/resolve'
import importType from '../core/importType'
import isStaticRequire from '../core/staticRequire'
import docsUrl from '../docsUrl'

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('no-internal-modules'),
},

schema: [
{
Expand Down
6 changes: 5 additions & 1 deletion src/rules/no-mutable-exports.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import docsUrl from '../docsUrl'

module.exports = {
meta: {
docs: {},
docs: {
url: docsUrl('no-mutable-exports'),
},
},

create: function (context) {
Expand Down
Loading