-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
178 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Adapted with gratitude from eslint-plugin-filenames (https://github.com/selaux/eslint-plugin-filenames) and used under an MIT license | ||
|
||
function getNodeName (node, options) { | ||
const op = options || [] | ||
|
||
if (node.type === 'Identifier') { | ||
return node.name | ||
} | ||
|
||
if (node.id && node.id.type === 'Identifier') { | ||
return node.id.name | ||
} | ||
|
||
if (op[2] && node.type === 'CallExpression' && node.callee.type === 'Identifier') { | ||
return node.callee.name | ||
} | ||
} | ||
|
||
module.exports = function getExportedName (programNode, options) { | ||
for (let i = 0; i < programNode.body.length; i += 1) { | ||
const node = programNode.body[i] | ||
|
||
// export default ... | ||
if (node.type === 'ExportDefaultDeclaration') { | ||
return getNodeName(node.declaration, options) | ||
} | ||
|
||
// module.exports = ... | ||
if (node.type === 'ExpressionStatement' && | ||
node.expression.type === 'AssignmentExpression' && | ||
node.expression.left.type === 'MemberExpression' && | ||
node.expression.left.object.type === 'Identifier' && | ||
node.expression.left.object.name === 'module' && | ||
node.expression.left.property.type === 'Identifier' && | ||
node.expression.left.property.name === 'exports' | ||
) { | ||
return getNodeName(node.expression.right, options) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Adapted with gratitude from eslint-plugin-filenames (https://github.com/selaux/eslint-plugin-filenames) and used under an MIT license | ||
|
||
const ignoredFilenames = [ '<text>', '<input>' ] | ||
|
||
module.exports = function isIgnoredFilename (filename) { | ||
return ignoredFilenames.indexOf(filename) !== -1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Adapted with gratitude from eslint-plugin-filenames (https://github.com/selaux/eslint-plugin-filenames) and used under an MIT license | ||
|
||
const path = require('path') | ||
|
||
module.exports = function parseFilename (filename) { | ||
const ext = path.extname(filename) | ||
|
||
return { | ||
dir: path.dirname(filename), | ||
base: path.basename(filename), | ||
ext: ext, | ||
name: path.basename(filename, ext), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Adapted with gratitude from eslint-plugin-filenames (https://github.com/selaux/eslint-plugin-filenames) and used under an MIT license | ||
|
||
module.exports = { | ||
rules: { | ||
'match-regex': require('./match-regex'), | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Adapted with gratitude from eslint-plugin-filenames (https://github.com/selaux/eslint-plugin-filenames) and used under an MIT license | ||
|
||
/** | ||
* @fileoverview Rule to ensure that filenames match a convention (default: camelCase) | ||
* @author Stefan Lau | ||
*/ | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Rule Definition | ||
// ------------------------------------------------------------------------------ | ||
|
||
const path = require('path'), | ||
parseFilename = require('../lib/parse-filename'), | ||
getExportedName = require('../lib/get-exported-name'), | ||
isIgnoredFilename = require('../lib/is-ignored-filename') | ||
|
||
module.exports = { | ||
meta: { | ||
schema: { | ||
type: 'array', | ||
minItems: 0, | ||
maxItems: 3, | ||
}, | ||
}, | ||
create: function (context) { | ||
const defaultRegexp = /^([a-z0-9]+)([A-Z][a-z0-9]+)*$/g, | ||
conventionRegexp = context.options[0] ? new RegExp(context.options[0]) : defaultRegexp, | ||
ignoreExporting = context.options[1] ? context.options[1] : false | ||
|
||
return { | ||
'Program': function (node) { | ||
const filename = context.getFilename(), | ||
absoluteFilename = path.resolve(filename), | ||
parsed = parseFilename(absoluteFilename), | ||
shouldIgnore = isIgnoredFilename(filename), | ||
isExporting = Boolean(getExportedName(node)), | ||
matchesRegex = conventionRegexp.test(parsed.name) | ||
|
||
if (shouldIgnore) return | ||
if (ignoreExporting && isExporting) return | ||
if (!matchesRegex) { | ||
context.report(node, | ||
`Filename '{{name}}' does not match the naming convention.`, | ||
{ name: parsed.base }, | ||
) | ||
} | ||
}, | ||
} | ||
}, | ||
} |