-
Notifications
You must be signed in to change notification settings - Fork 821
Vue Casing #4034
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
indirectlylit
merged 26 commits into
learningequality:develop
from
christianmemije:VueCasing
Jul 19, 2018
Merged
Vue Casing #4034
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
6eaed87
Require component name properties to be PascalCase
christianmemije 26e0deb
Prettify
christianmemije 179aa83
Rename core api components to use PascalCase
christianmemije 745014b
Add component names to all components missing names
christianmemije 6f8e257
Clean up root component names
christianmemije cfcce9e
Require vue components who are named index.vue to have parent dir mat…
christianmemije 4c68e09
Rename core api component filenames
christianmemije 8e17ffb
Rename core api component filenames
christianmemije 554e723
Rename coach vue files
christianmemije 8f0a009
Rename device vue files
christianmemije c91d5b0
Rename pdf vue filenames
christianmemije 9ad83c0
Rename facility filenames
christianmemije 5ac600f
Rename Learn vue filenames
christianmemije 9dbf0ee
Rename Setup wizard vue filenames
christianmemije afd40f2
Rename Style guide vue filenames
christianmemije 85abc9e
Rename User vue filenames
christianmemije 701f3fa
Rename some directories
christianmemije 757a102
Rename the rest of the files
christianmemije 193cb88
Merge remote-tracking branch 'upstream/develop' into VueCasing
christianmemije ecceac6
Fix tests
christianmemije 95f1a49
Make component registration PascalCase
christianmemije 5eba45e
Change template component references to PascalCase
christianmemije 9cfcc6b
Convert rules to plugin
christianmemije dae1633
Resolve merge conflict
christianmemije 401f8b7
Fix eslint-plugin-kolibri pos in package.json
christianmemije 1bae00a
Keep router-view kebab-case
christianmemije File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
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
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,18 @@ | ||
| /** | ||
| * @fileoverview Custom rules. | ||
| * @author Learning Equality | ||
| */ | ||
| 'use strict'; | ||
|
|
||
| //------------------------------------------------------------------------------ | ||
| // Requirements | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
| var requireIndex = require('requireindex'); | ||
|
|
||
| //------------------------------------------------------------------------------ | ||
| // Plugin Definition | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
| // import all rules in lib/rules | ||
| module.exports.rules = requireIndex(__dirname + '/rules'); |
64 changes: 64 additions & 0 deletions
64
eslint-plugin-kolibri/lib/rules/vue-component-registration-casing.js
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,64 @@ | ||
| /** | ||
| * @fileoverview Requires specific casing for component registration | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| const utils = require('eslint-plugin-vue/lib/utils'); | ||
| const casing = require('eslint-plugin-vue/lib/utils/casing'); | ||
|
|
||
| const allowedCaseOptions = ['PascalCase', 'camelCase', 'snake_case']; | ||
|
|
||
| function create(context) { | ||
| const selectedCase = context.options[0]; | ||
| const caseType = | ||
| allowedCaseOptions.indexOf(selectedCase) !== -1 ? selectedCase : allowedCaseOptions[0]; | ||
| const converter = casing.getConverter(caseType); | ||
|
|
||
| return utils.executeOnVue(context, obj => { | ||
| const node = obj.properties.find( | ||
| p => | ||
| p.type === 'Property' && | ||
| p.key.type === 'Identifier' && | ||
| p.key.name === 'components' && | ||
| p.value.type === 'ObjectExpression' | ||
| ); | ||
|
|
||
| if (!node) { | ||
| return; | ||
| } | ||
|
|
||
| const items = node.value.properties; | ||
| for (const item of items) { | ||
| const componentName = item.key.name; | ||
| const convertedName = converter(componentName); | ||
| if (convertedName !== componentName) { | ||
| context.report({ | ||
| node: item, | ||
| message: 'Component "{{componentName}}" is not in {{caseType}}.', | ||
| data: { | ||
| componentName, | ||
| caseType, | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| module.exports = { | ||
| meta: { | ||
| docs: { | ||
| description: 'enforce specific casing for component registration', | ||
| category: undefined, | ||
| url: undefined, | ||
| }, | ||
| fixable: undefined, | ||
| schema: [ | ||
| { | ||
| enum: allowedCaseOptions, | ||
| }, | ||
| ], | ||
| }, | ||
| create, | ||
| }; |
87 changes: 87 additions & 0 deletions
87
eslint-plugin-kolibri/lib/rules/vue-filename-and-component-name-match.js
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,87 @@ | ||
| /** | ||
| * @fileoverview Requires filename and component names for vue files to match | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| const path = require('path'); | ||
| const utils = require('eslint-plugin-vue/lib/utils'); | ||
|
|
||
| function create(context) { | ||
| return utils.executeOnVue(context, obj => { | ||
| const filePath = context.getFilename(); | ||
|
|
||
| // Skip if not .vue file | ||
| if (!filePath.endsWith('vue')) { | ||
| return; | ||
| } | ||
|
|
||
| const node = obj.properties.find( | ||
| item => item.type === 'Property' && item.key.name === 'name' && item.value.type === 'Literal' | ||
| ); | ||
|
|
||
| // Components require a name | ||
| if (!node) { | ||
| context.report({ | ||
| message: 'Component is missing a component name', | ||
| loc: { | ||
| start: { | ||
| line: 1, | ||
| column: 1, | ||
| }, | ||
| end: { | ||
| line: 1, | ||
| column: 1, | ||
| }, | ||
| }, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| const componentName = node.value.value; | ||
|
|
||
| const fileName = path.basename(filePath, '.vue'); | ||
| const parentDirName = path.basename(path.dirname(filePath)); | ||
|
|
||
| // If index.vue, parent dir should match component name | ||
| if (fileName === 'index') { | ||
| if (componentName !== parentDirName) { | ||
| context.report({ | ||
| node: node.value, | ||
| message: | ||
| 'Parent dir name "{{parentDirName}}" does not match component name "{{componentName}}".', | ||
| data: { | ||
| parentDirName, | ||
| componentName, | ||
| }, | ||
| }); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // Filename should match component name. | ||
| // Assumes component name is already PascalCase since we use vue/name-property-casing | ||
| if (componentName !== fileName) { | ||
| context.report({ | ||
| node: node.value, | ||
| message: 'Filename "{{fileName}}" does not match component name {{componentName}}.', | ||
| data: { | ||
| fileName, | ||
| componentName, | ||
| }, | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| module.exports = { | ||
| meta: { | ||
| docs: { | ||
| description: 'enforce filenames and component names to match', | ||
| category: undefined, | ||
| url: undefined, | ||
| }, | ||
| fixable: undefined, | ||
| }, | ||
| create, | ||
| }; |
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,21 @@ | ||
| { | ||
| "name": "eslint-plugin-kolibri", | ||
| "version": "0.0.1", | ||
| "description": "Custom rules.", | ||
| "author": "Learning Equality", | ||
| "main": "lib/index.js", | ||
| "scripts": { | ||
| "test": "mocha tests --recursive" | ||
| }, | ||
| "dependencies": { | ||
| "requireindex": "^1.1.0" | ||
| }, | ||
| "devDependencies": { | ||
| "eslint": "^3.9.1", | ||
| "mocha": "^3.1.2" | ||
| }, | ||
| "engines": { | ||
| "node": ">=0.10.0" | ||
| }, | ||
| "license": "MIT" | ||
| } |
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
Oops, something went wrong.
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.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.