-
Notifications
You must be signed in to change notification settings - Fork 63
Update filenames #578
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
Merged
Merged
Update filenames #578
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
15639d6
update filenames
gracepark c03d25b
bring in filenames match regex to github
gracepark 7520260
add back in test examples;
gracepark 725f1a1
bring in filenames to github rules
gracepark 813592d
rule docs for filenames match regex
gracepark 259194f
remove filenames plugin
gracepark a78d1ef
update items max and min
gracepark 3116c0c
Update docs/rules/filenames-match-regex.md
gracepark e86d155
add comment
gracepark b5369f3
Merge remote-tracking branch 'refs/remotes/origin/filenames-fix' into…
gracepark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,35 @@ | ||
| # Ensure filenames match a regex naming convention (`github/filenames-match-regex`) | ||
|
|
||
| 💼 This rule is enabled in the ✅ `recommended` config. | ||
|
|
||
| <!-- end auto-generated rule header --> | ||
|
|
||
| ## Rule Details | ||
|
|
||
| TRule to ensure that filenames match a convention, with a default of camelCase. | ||
|
|
||
| 👎 Examples of **incorrect** filename for this default rule: | ||
|
|
||
| `file-name.js` | ||
|
|
||
| 👍 Examples of **correct** code for this rule: | ||
|
|
||
| `fileName.js` | ||
|
|
||
| ## Options | ||
|
|
||
| regex - Regex to match the filename structure. Defaults to camelCase. | ||
|
|
||
|
|
||
| ```json | ||
| { | ||
| "filenames-match-regex": [ | ||
| "error", | ||
| "^[a-z0-9-]+(.[a-z0-9-]+)?$" | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| ## Version | ||
|
|
||
| 4.3.2 | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,49 @@ | ||
| const path = require('path') | ||
| const parseFilename = require('../utils/parse-filename') | ||
| const getExportedName = require('../utils/get-exported-name') | ||
| const isIgnoredFilename = require('../utils/is-ignored-filename') | ||
|
|
||
| module.exports = { | ||
| meta: { | ||
| type: 'problem', | ||
| docs: { | ||
| description: 'ensure filenames match a regex naming convention', | ||
| url: require('../url')(module), | ||
| }, | ||
| schema: { | ||
| type: 'array', | ||
| minItems: 0, | ||
| maxItems: 1, | ||
| items: [ | ||
| { | ||
| type: 'string', | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
|
|
||
| create(context) { | ||
| const defaultRegexp = /^([a-z0-9]+)([A-Z][a-z0-9]+)*$/g | ||
| const conventionRegexp = context.options[0] ? new RegExp(context.options[0]) : defaultRegexp | ||
| const ignoreExporting = context.options[1] ? context.options[1] : false | ||
|
|
||
| return { | ||
| Program(node) { | ||
| const filename = context.getFilename() | ||
| const absoluteFilename = path.resolve(filename) | ||
| const parsed = parseFilename(absoluteFilename) | ||
| const shouldIgnore = isIgnoredFilename(filename) | ||
| const isExporting = Boolean(getExportedName(node)) | ||
| const matchesRegex = conventionRegexp.test(parsed.name) | ||
|
|
||
| if (shouldIgnore) return | ||
| if (ignoreExporting && isExporting) return | ||
| if (!matchesRegex) { | ||
| context.report(node, "Filename '{{name}}' does not match the regex naming convention.", { | ||
| name: parsed.base, | ||
| }) | ||
| } | ||
| }, | ||
| } | ||
| }, | ||
| } |
This file contains hidden or 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,37 @@ | ||
| 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] | ||
|
|
||
| if (node.type === 'ExportDefaultDeclaration') { | ||
| return getNodeName(node.declaration, options) | ||
| } | ||
|
|
||
| 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 hidden or 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,5 @@ | ||
| const ignoredFilenames = ['<text>', '<input>'] | ||
|
|
||
| module.exports = function isIgnoredFilename(filename) { | ||
| return ignoredFilenames.indexOf(filename) !== -1 | ||
| } |
This file contains hidden or 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,12 @@ | ||
| const path = require('path') | ||
|
|
||
| module.exports = function parseFilename(filename) { | ||
| const ext = path.extname(filename) | ||
|
|
||
| return { | ||
| dir: path.dirname(filename), | ||
| base: path.basename(filename), | ||
| ext, | ||
| name: path.basename(filename, ext), | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,18 +1,18 @@ | ||
| import github from 'eslint-plugin-github' | ||
|
|
||
| export default [ | ||
| github.getFlatConfigs().browser, | ||
| github.getFlatConfigs().recommended, | ||
| github.getFlatConfigs().browser, | ||
| github.getFlatConfigs().react, | ||
| ...github.getFlatConfigs().typescript, | ||
| { | ||
| files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'], | ||
| ignores: ['eslint.config.mjs'], | ||
| rules: { | ||
| 'github/array-foreach': 'error', | ||
| 'github/async-preventdefault': 'warn', | ||
| 'github/no-then': 'error', | ||
| 'github/no-blur': 'error', | ||
| 'github/async-preventdefault': 'error', | ||
| }, | ||
| }, | ||
| ] |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.