-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
UI: Refactors the code-mirror linting #4866
Merged
Merged
Changes from all commits
Commits
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 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,33 @@ | ||
import Service, { inject as service } from '@ember/service'; | ||
import { get } from '@ember/object'; | ||
import lint from 'consul-ui/utils/editor/lint'; | ||
const MODES = [ | ||
{ | ||
name: 'JSON', | ||
mime: 'application/json', | ||
mode: 'javascript', | ||
ext: ['json', 'map'], | ||
alias: ['json5'], | ||
}, | ||
{ | ||
name: 'HCL', | ||
mime: 'text/x-ruby', | ||
mode: 'ruby', | ||
ext: ['rb'], | ||
alias: ['jruby', 'macruby', 'rake', 'rb', 'rbx'], | ||
}, | ||
{ name: 'YAML', mime: 'text/x-yaml', mode: 'yaml', ext: ['yaml', 'yml'], alias: ['yml'] }, | ||
]; | ||
|
||
export default Service.extend({ | ||
dom: service('dom'), | ||
modes: function() { | ||
return MODES; | ||
}, | ||
lint: function() { | ||
return lint(...arguments); | ||
}, | ||
getEditor: function(element) { | ||
return get(this, 'dom').element('textarea + div', element).CodeMirror; | ||
}, | ||
}); |
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,12 @@ | ||
import { moduleFor, test } from 'ember-qunit'; | ||
|
||
moduleFor('service:code-mirror/linter', 'Unit | Service | code mirror/linter', { | ||
// Specify the other units that are required for this test. | ||
needs: ['service:dom'], | ||
}); | ||
|
||
// Replace this with your real tests. | ||
test('it exists', function(assert) { | ||
let service = this.subject(); | ||
assert.ok(service); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see we're doing a
item.name.toLowerCase() == syntax.toLowerCase()
on this syntax param. It caught me a bit by surprise given it wasn't an alias or a name (hcl
) and I was wondering how it knew to select HCL. Maybe just worth making it an alias instead of doing that for readability?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean an ember
alias
yeah? Do you know how that would help here? I thought analias
was to point one property to another?The
toLowerCase
was just good hygiene really, I took the mode specs from the code-mirror source and the properties/'syntax names' are in uppercase, and I didn't want to change that, so I thought there would always be the slight chance of confusion as to whether to saysyntax="HCL"
orsyntax="hcl"
Actually looking at it I could at least use
===
not==
Anyway, lemme know on the alias thing, maybe I've misunderstood what you meant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I meant https://github.com/hashicorp/consul/pull/4866/files/98acdadaf1a3597bd3e36247b6e321aa3b1826c3#diff-c79b0ce21a1201a8516d52bd57f5404bR17 one of those things. I might be really confused.
Just hygienic regardless so LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, of course (sorry just realized what you meant now), you're not confused, I am!
This will end up going in post 1.4.0, but if you are interested in the background (more or less), here goes:
So, that JSON blob is taken directly from the codemirror
modes.js
file (I think its called that). That file is massive and contains a load of stuff I'll never need (it has ALL the different modes it supports). So I took the bits I need from it, but I want to leave it as close the original source as possible.The HCL part of the blob is actually the 'ruby' one from codemirror, I just changed the
name:
but kept it uppercase to be consistent to the other names. So essentially HCL 'mode' is actually 'ruby' mode. I chose thesyntax
name for the attribute as it made sense to me, and I didn't want to usename
as that means something else in HTML andmode
didn't seem quite right as this isruby
mode..but hcl :STo choose the syntax/mode, it just looks through the JSON blob, looking for
'HCL'.toLowerCase()
. I could have just hardcoded the names in the JSON blob to be lowercase, but see above about wanting to change as little as possible.