Skip to content

Commit

Permalink
Merge pull request #249 from okkez/eslint
Browse files Browse the repository at this point in the history
Introduce ESLint
  • Loading branch information
okkez authored Jul 18, 2018
2 parents 211afb7 + 003da56 commit cc895e7
Show file tree
Hide file tree
Showing 21 changed files with 890 additions and 376 deletions.
45 changes: 45 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module.exports = {
"env": {
"browser": true,
"es6": true
},
"extends": [
"eslint:recommended",
"plugin:vue/recommended"
],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"globals": {
"$": true,
"Rails": true,
"Vue": true
},
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
],
"no-console": [
"off"
],
"no-unused-vars": [
"off", {
"argsIgnorePattern": "^_"
}
]
}
};
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ before_install:
install:
- bundle -v
- gem i bundler
- sudo sh -c 'curl -L https://toolbelt.treasuredata.com/sh/install-ubuntu-trusty-td-agent2.sh | sh'
- sudo sh -c 'curl -L https://toolbelt.treasuredata.com/sh/install-ubuntu-trusty-td-agent3.sh | sh'
- bin/setup
40 changes: 20 additions & 20 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
// layout file, like app/views/layouts/application.html.erb

console.log('Hello World from Webpacker')
console.log("Hello World from Webpacker");

import jQuery from 'jquery/dist/jquery'
import jQuery from "jquery/dist/jquery";

window.$ = jQuery
window.jQuery = jQuery
window.$ = jQuery;
window.jQuery = jQuery;

import Rails from 'rails-ujs/lib/assets/compiled/rails-ujs.js'
import Rails from "rails-ujs/lib/assets/compiled/rails-ujs.js";

window.Rails = Rails
Rails.start()
window.Rails = Rails;
Rails.start();

import 'popper.js/dist/popper'
import 'bootstrap/dist/js/bootstrap'
import 'datatables.net/js/jquery.dataTables'
import 'startbootstrap-sb-admin/js/sb-admin'
import 'startbootstrap-sb-admin/js/sb-admin-datatables'
import "popper.js/dist/popper";
import "bootstrap/dist/js/bootstrap";
import "datatables.net/js/jquery.dataTables";
import "startbootstrap-sb-admin/js/sb-admin";
import "startbootstrap-sb-admin/js/sb-admin-datatables";

import Vue from 'vue/dist/vue.esm'
import Vue from "vue/dist/vue.esm";

Vue.filter('to_json', function (value) {
return JSON.stringify(value);
})
Vue.filter("to_json", function (value) {
return JSON.stringify(value);
});

window.Vue = Vue
window.Vue = Vue;

import '../stylesheets/application.scss'
import "../stylesheets/application.scss";

$(document).ready(() => {
$("[data-toggle=tooltip]").tooltip()
})
$("[data-toggle=tooltip]").tooltip();
});
20 changes: 10 additions & 10 deletions app/javascript/packs/aws_credential.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
"use strict";

import ConfigField from './config_field'
import ConfigField from "./config_field";

const AwsCredential = {
template: "#vue-aws-credential",
Expand All @@ -22,12 +22,12 @@ const AwsCredential = {
"instanceProfileCredentials",
"sharedCredentials"
]
}
};
},

computed: {
token: function() {
return Rails.csrfToken()
return Rails.csrfToken();
}
},

Expand All @@ -37,25 +37,25 @@ const AwsCredential = {

methods: {
onChange: function() {
this.updateSection()
this.updateSection();
},

updateSection: function() {
$.ajax({
method: "GET",
url: "/api/config_definitions",
headers: {
'X-CSRF-Token': this.token
"X-CSRF-Token": this.token
},
data: {
type: this.pluginType,
name: this.pluginName
}
}).then((data) => {
this.credentialOptions = data["awsCredentialOptions"][this.credentialType]
})
this.credentialOptions = data["awsCredentialOptions"][this.credentialType];
});
}
}
}
};

export { AwsCredential as default }
export { AwsCredential as default };
70 changes: 33 additions & 37 deletions app/javascript/packs/codemirror.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import CodeMirror from 'codemirror/lib/codemirror'
import 'lodash/lodash'
/* global _ */
"use strict";
import CodeMirror from "codemirror/lib/codemirror";
import "lodash/lodash";

// See: http://codemirror.net/doc/manual.html#modeapi
// and sample mode files: https://github.com/codemirror/CodeMirror/tree/master/mode

CodeMirror.defineMode('fluentd', function(){
CodeMirror.defineMode("fluentd", function(){
return {
startState: function(aa){
return { "context" : null };
Expand All @@ -21,40 +23,34 @@ CodeMirror.defineMode('fluentd', function(){
}

switch(stream.peek()){
case "#":
stream.skipToEnd();
return "comment";
break;
case "<":
state.context = "inner-bracket";
stream.pos += 1;
case "#":
stream.skipToEnd();
return "comment";
case "<":
state.context = "inner-bracket";
stream.pos += 1;
return "keyword";
case ">":
stream.pos += 1;
state.context = "inner-definition";
return "keyword";
default:
switch(state.context){
case "inner-bracket":
stream.eat(/[^#<>]+/);
return "keyword";
break;
case ">":
stream.pos += 1;
case "inner-definition":
stream.eatWhile(/[^ \t#]/);
state.context = "inner-definition-keyword-appeared";
return "variable";
case "inner-definition-keyword-appeared":
stream.eatWhile(/[^#]/);
state.context = "inner-definition";
return "keyword";
break;
return "builtin";
default:
switch(state.context){
case "inner-bracket":
stream.eat(/[^#<>]+/);
return "keyword";
break;
case "inner-definition":
var key = stream.eatWhile(/[^ \t#]/);
state.context = "inner-definition-keyword-appeared";
return "variable";
break;
case "inner-definition-keyword-appeared":
var key = stream.eatWhile(/[^#]/);
state.context = "inner-definition";
return "builtin";
break;
default:
stream.eat(/[^<>#]+/);
return "string";
}
stream.eat(/[^<>#]+/);
return "string";
}
}
}
};
Expand All @@ -70,18 +66,18 @@ function codemirrorify(el) {
}

$(function(){
$('.js-fluentd-config-editor').each(function(_, el){
$(".js-fluentd-config-editor").each(function(_, el){
codemirrorify(el);
});
});

Vue.directive('config-editor', {
Vue.directive("config-editor", {
bind: function(el, binding, vnode, oldVnode){
// NOTE: needed delay for waiting CodeMirror setup
_.delay(function(textarea){
let cm = codemirrorify(textarea);
// textarea.codemirror = cm; // for test, but doesn't work for now (working on Chrome, but Poltergeist not)
cm.on('change', function(code_mirror){
cm.on("change", function(code_mirror){
// bridge Vue - CodeMirror world
el.dataset.content = code_mirror.getValue();
});
Expand Down
51 changes: 26 additions & 25 deletions app/javascript/packs/config_field.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'
import 'lodash/lodash'
/* global _ */
"use strict";
import "lodash/lodash";

const ConfigField = {
template: "#vue-config-field",
Expand All @@ -16,77 +17,77 @@ const ConfigField = {
expression: null,
timeFormat: null,
textValue: null,
}
};
},

filters: {
humanize: function(value) {
return _.capitalize(value.replace(/_/g, " "))
return _.capitalize(value.replace(/_/g, " "));
}
},

mounted: function() {
if (this.option.name === "expression") {
this.expression = this.initialExpression
this.expression = this.initialExpression;
} else if (this.option.name === "time_format") {
this.timeFormat = this.initialTimeFormat
this.timeFormat = this.initialTimeFormat;
} else {
this.textValue = this.initialTextValue || this.option.default
this.textValue = this.initialTextValue || this.option.default;
}
},

updated: function() {
if (this.option.name === "expression") {
this.expression = this.initialExpression
this.expression = this.initialExpression;
}
if (this.option.name === "time_format") {
this.timeFormat = this.initialTimeFormat
this.timeFormat = this.initialTimeFormat;
}
this.$nextTick(() => {
console.log("config-field updated")
$("[data-toggle=tooltip]").tooltip("dispose")
$("[data-toggle=tooltip]").tooltip("enable")
})
console.log("config-field updated");
$("[data-toggle=tooltip]").tooltip("dispose");
$("[data-toggle=tooltip]").tooltip("enable");
});
},

watch: {
"expression": function(newValue, oldValue) {
"expression": function(_newValue, _oldValue) {
this.$emit("change-parse-config", {
"expression": this.expression,
"timeFormat": this.timeFormat
})
});
},
"timeFormat": function(newValue, oldValue) {
"timeFormat": function(_newValue, _oldValue) {
this.$emit("change-parse-config", {
"expression": this.expression,
"timeFormat": this.timeFormat
})
});
}
},

methods: {
inputId: function(pluginType, option) {
if (pluginType === "output") {
return `setting_${option.name}`
return `setting_${option.name}`;
} else {
return `setting_${_.snakeCase(pluginType)}_0__${option.name}`
return `setting_${_.snakeCase(pluginType)}_0__${option.name}`;
}
},
inputName: function(pluginType, option) {
if (pluginType === "output") {
return `setting[${option.name}]`
return `setting[${option.name}]`;
} else {
return `setting[${_.snakeCase(pluginType)}[0]][${option.name}]`
return `setting[${_.snakeCase(pluginType)}[0]][${option.name}]`;
}
},
checked: function(checked) {
if (checked === true || checked === "true") {
return "checked"
return "checked";
} else {
return ""
return "";
}
}
}
}
};

export { ConfigField as default }
export { ConfigField as default };
Loading

0 comments on commit cc895e7

Please sign in to comment.