diff --git a/ui/packages/consul-ui/app/components/code-editor/index.js b/ui/packages/consul-ui/app/components/code-editor/index.js index 65566d159b76..9804078cc7d4 100644 --- a/ui/packages/consul-ui/app/components/code-editor/index.js +++ b/ui/packages/consul-ui/app/components/code-editor/index.js @@ -11,13 +11,10 @@ const DEFAULTS = { lineNumbers: true, theme: 'hashi', showCursorWhenSelecting: true, - gutters: ['CodeMirror-lint-markers'], - lint: true, }; export default Component.extend({ settings: service('settings'), dom: service('dom'), - helper: service('code-mirror/linter'), classNames: ['code-editor'], readonly: false, syntax: '', @@ -26,7 +23,6 @@ export default Component.extend({ oninput: function () {}, init: function () { this._super(...arguments); - set(this, 'modes', this.helper.modes()); }, didReceiveAttrs: function () { this._super(...arguments); @@ -51,7 +47,6 @@ export default Component.extend({ const editor = this.editor; editor.setOption('mode', mode.mime); - this.helper.lint(editor, mode.mode); set(this, 'mode', mode); } }, @@ -76,7 +71,8 @@ export default Component.extend({ }); set(this, 'value', $code.firstChild.wholeText); } - set(this, 'editor', this.helper.getEditor(this.element)); + // set(this, 'editor', this.helper.getEditor(this.element)); + set(this, 'editor', this.dom.element('textarea + div', this.element).CodeMirror); this.settings.findBySlug('code-editor').then((mode) => { const modes = this.modes; const syntax = this.syntax; diff --git a/ui/packages/consul-ui/app/services/code-mirror/linter.js b/ui/packages/consul-ui/app/services/code-mirror/linter.js deleted file mode 100644 index 66b4a3dc4d36..000000000000 --- a/ui/packages/consul-ui/app/services/code-mirror/linter.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright (c) HashiCorp, Inc. - * SPDX-License-Identifier: BUSL-1.1 - */ - -import Service, { inject as service } from '@ember/service'; -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'] }, - { - name: 'XML', - mime: 'application/xml', - mode: 'xml', - htmlMode: false, - matchClosing: true, - alignCDATA: false, - ext: ['xml'], - alias: ['xml'], - }, -]; - -export default class LinterService extends Service { - @service('dom') - dom; - - modes() { - return MODES; - } - - lint() { - return lint(...arguments); - } - - getEditor(element) { - return this.dom.element('textarea + div', element).CodeMirror; - } -} diff --git a/ui/packages/consul-ui/app/utils/editor/lint.js b/ui/packages/consul-ui/app/utils/editor/lint.js deleted file mode 100644 index 4c3e824e44bb..000000000000 --- a/ui/packages/consul-ui/app/utils/editor/lint.js +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (c) HashiCorp, Inc. - * SPDX-License-Identifier: BUSL-1.1 - */ - -/*global CodeMirror*/ - -// CodeMirror doesn't seem to have anyway to hook into whether a mode -// has already loaded, or when a mode has finished loading -// follow more or less what CodeMirror does but doesn't expose -// see codemirror/addon/mode/loadmode.js - -export const createLoader = function ( - $$ = document.getElementsByTagName.bind(document), - CM = CodeMirror -) { - CM.registerHelper('lint', 'ruby', function (text) { - return []; - }); - return function (editor, mode, cb) { - let scripts = [...$$('script')]; - const loaded = scripts.find(function (item) { - return item.src.indexOf(`/codemirror/mode/${mode}/${mode}.js`) !== -1; - }); - CM.autoLoadMode(editor, mode); - if (loaded) { - cb(); - } else { - scripts = [...$$('script')]; - CM.on(scripts[0], 'load', function () { - cb(); - }); - } - }; -}; -const load = createLoader(); -export default function (editor, mode) { - load(editor, mode, function () { - if (editor.getValue().trim().length) { - editor.performLint(); - } - }); -} diff --git a/ui/packages/consul-ui/ember-cli-build.js b/ui/packages/consul-ui/ember-cli-build.js index 79f67e209797..d63ff71d67d1 100644 --- a/ui/packages/consul-ui/ember-cli-build.js +++ b/ui/packages/consul-ui/ember-cli-build.js @@ -206,11 +206,7 @@ module.exports = function (defaults, $ = process.env) { }, codemirror: { keyMaps: ['sublime'], - addonFiles: [ - 'lint/lint.css', - 'lint/yaml-lint.js', - 'mode/loadmode.js', - ], + addonFiles: ['mode/loadmode.js'], }, sassOptions: { implementation: require('sass'), @@ -268,27 +264,6 @@ module.exports = function (defaults, $ = process.env) { // CSS.escape polyfill app.import('node_modules/css.escape/css.escape.js', { outputFile: 'assets/css.escape.js' }); - // Possibly dynamically loaded via CodeMirror linting. See components/code-editor.js - app.import('node_modules/codemirror/mode/javascript/javascript.js', { - outputFile: 'assets/codemirror/mode/javascript/javascript.js', - }); - - // HCL/Ruby linting support. Possibly dynamically loaded via CodeMirror linting. See components/code-editor.js - app.import('node_modules/codemirror/mode/ruby/ruby.js', { - outputFile: 'assets/codemirror/mode/ruby/ruby.js', - }); - - // YAML linting support. Possibly dynamically loaded via CodeMirror linting. See components/code-editor.js - app.import('node_modules/js-yaml/dist/js-yaml.js', { - outputFile: 'assets/codemirror/mode/yaml/yaml.js', - }); - app.import('node_modules/codemirror/mode/yaml/yaml.js', { - outputFile: 'assets/codemirror/mode/yaml/yaml.js', - }); - // XML linting support. Possibly dynamically loaded via CodeMirror linting. See services/code-mirror/linter.js - app.import('node_modules/codemirror/mode/xml/xml.js', { - outputFile: 'assets/codemirror/mode/xml/xml.js', - }); // metrics-providers app.import('vendor/metrics-providers/consul.js', { outputFile: 'assets/metrics-providers/consul.js', diff --git a/ui/packages/consul-ui/tests/unit/services/code-mirror/linter-test.js b/ui/packages/consul-ui/tests/unit/services/code-mirror/linter-test.js deleted file mode 100644 index ec7c35002e39..000000000000 --- a/ui/packages/consul-ui/tests/unit/services/code-mirror/linter-test.js +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright (c) HashiCorp, Inc. - * SPDX-License-Identifier: BUSL-1.1 - */ - -import { module, test } from 'qunit'; -import { setupTest } from 'ember-qunit'; - -module('Unit | Service | code mirror/linter', function (hooks) { - setupTest(hooks); - - // Replace this with your real tests. - test('it exists', function (assert) { - let service = this.owner.lookup('service:code-mirror/linter'); - assert.ok(service); - }); -});