From 4203ba64749c054abcf02772656ac0e13d2f89ba Mon Sep 17 00:00:00 2001 From: hc-github-team-consul-core Date: Fri, 13 Sep 2024 16:48:48 -0400 Subject: [PATCH] Backport of [ui] Prettify ember-cli-build into release/1.19.x (#21733) [ui] Prettify ember-cli-build (#21731) * Missed prettification at a pre-merge step earlier * Missed lint-removal Co-authored-by: Phil Renaud --- .../app/components/code-editor/index.js | 1 - .../app/services/code-mirror/linter.js | 5 --- .../consul-ui/app/utils/editor/lint.js | 43 ------------------- ui/packages/consul-ui/ember-cli-build.js | 6 +-- 4 files changed, 1 insertion(+), 54 deletions(-) delete mode 100644 ui/packages/consul-ui/app/utils/editor/lint.js 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 e04b3629db71..012f9698dde9 100644 --- a/ui/packages/consul-ui/app/components/code-editor/index.js +++ b/ui/packages/consul-ui/app/components/code-editor/index.js @@ -49,7 +49,6 @@ export default Component.extend({ const editor = this.editor; editor.setOption('mode', mode.mime); - this.helper.lint(editor, mode.mode); set(this, 'mode', mode); } }, diff --git a/ui/packages/consul-ui/app/services/code-mirror/linter.js b/ui/packages/consul-ui/app/services/code-mirror/linter.js index 66b4a3dc4d36..74a0a45b0140 100644 --- a/ui/packages/consul-ui/app/services/code-mirror/linter.js +++ b/ui/packages/consul-ui/app/services/code-mirror/linter.js @@ -4,7 +4,6 @@ */ import Service, { inject as service } from '@ember/service'; -import lint from 'consul-ui/utils/editor/lint'; const MODES = [ { name: 'JSON', @@ -41,10 +40,6 @@ export default class LinterService extends Service { 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..ecfdc1b35ac6 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: ['lint/lint.css', 'lint/yaml-lint.js', 'mode/loadmode.js'], }, sassOptions: { implementation: require('sass'),