Skip to content

Commit

Permalink
Misc JS linting and naming tweaks (go-gitea#10652)
Browse files Browse the repository at this point in the history
- lowercase all js filenames except Vue components
- enable new lint rules, mostly focused on shorter code
- autofix new lint violations
- apply misc transformations indexOf -> includes and onevent-> addEventListener

Co-authored-by: Antoine GIRARD <[email protected]>
  • Loading branch information
silverwind and sapk authored Mar 11, 2020
1 parent 984b85c commit e03d627
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 96 deletions.
11 changes: 9 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extends:
- eslint:recommended

ignorePatterns:
- /web_src/js/vendor
- /web_src/js/vendor

parserOptions:
ecmaVersion: 2020
Expand All @@ -26,19 +26,22 @@ globals:

rules:
arrow-body-style: [0]
arrow-parens: [2, always]
camelcase: [0]
comma-dangle: [2, only-multiline]
consistent-return: [0]
default-case: [0]
func-names: [0]
import/extensions: [0]
import/extensions: [2, always, {ignorePackages: true}]
import/prefer-default-export: [0]
max-len: [0]
multiline-comment-style: [2, separate-lines]
newline-per-chained-call: [0]
no-alert: [0]
no-cond-assign: [2, except-parens]
no-console: [1, {allow: [info, warn, error]}]
no-continue: [0]
no-eq-null: [2]
no-mixed-operators: [0]
no-multi-assign: [0]
no-new: [0]
Expand All @@ -49,8 +52,12 @@ rules:
no-unused-vars: [2, {args: all, argsIgnorePattern: ^_, varsIgnorePattern: ^_, ignoreRestSiblings: true}]
no-use-before-define: [0]
no-var: [2]
object-curly-spacing: [2, never]
one-var-declaration-per-line: [0]
one-var: [0]
operator-linebreak: [2, after]
prefer-const: [2, {destructuring: all}]
prefer-destructuring: [0]
quotes: [2, single, {avoidEscape: true, allowTemplateLiterals: true}]
radix: [2, as-needed]
semi: [2, always, {omitLastInOneLineBlock: true}]
2 changes: 1 addition & 1 deletion web_src/js/features/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default async function initClipboard() {
const els = document.querySelectorAll('.clipboard');
if (!els || !els.length) return;

const { default: ClipboardJS } = await import(/* webpackChunkName: "clipboard" */'clipboard');
const {default: ClipboardJS} = await import(/* webpackChunkName: "clipboard" */'clipboard');

const clipboard = new ClipboardJS(els);
clipboard.on('success', (e) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { svg } from '../utils.js';
import {svg} from '../utils.js';

const { AppSubUrl } = window.config;
const {AppSubUrl} = window.config;

export default function initContextPopups() {
const refIssues = $('.ref-issue');
Expand All @@ -14,7 +14,7 @@ export default function initContextPopups() {

function issuePopup(owner, repo, index, $element) {
$.get(`${AppSubUrl}/api/v1/repos/${owner}/${repo}/issues/${index}`, (issue) => {
const createdAt = new Date(issue.created_at).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' });
const createdAt = new Date(issue.created_at).toLocaleDateString(undefined, {year: 'numeric', month: 'short', day: 'numeric'});

let body = issue.body.replace(/\n+/g, ' ');
if (body.length > 85) {
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/dropzone.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default async function createDropzone(el, opts) {
const [{ default: Dropzone }] = await Promise.all([
const [{default: Dropzone}] = await Promise.all([
import(/* webpackChunkName: "dropzone" */'dropzone'),
import(/* webpackChunkName: "dropzone" */'dropzone/dist/dropzone.css'),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default async function initGitGraph() {
const graphCanvas = document.getElementById('graph-canvas');
if (!graphCanvas) return;

const { default: gitGraph } = await import(/* webpackChunkName: "gitgraph" */'../vendor/gitGraph.js');
const {default: gitGraph} = await import(/* webpackChunkName: "gitgraph" */'../vendor/gitgraph.js');

const graphList = [];
$('#graph-raw-list li span.node-relation').each(function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Vue from 'vue';

const { AppSubUrl, heatmapUser } = window.config;
const {AppSubUrl, heatmapUser} = window.config;

export default async function initHeatmap() {
const el = document.getElementById('user-heatmap');
if (!el) return;

const { CalendarHeatmap } = await import(/* webpackChunkName: "userheatmap" */'vue-calendar-heatmap');
const {CalendarHeatmap} = await import(/* webpackChunkName: "userheatmap" */'vue-calendar-heatmap');
Vue.component('calendarHeatmap', CalendarHeatmap);

const vueDelimeters = ['${', '}'];
Expand Down Expand Up @@ -59,7 +59,7 @@ export default async function initHeatmap() {
const chartData = [];
for (let i = 0; i < chartRawData.length; i++) {
self.totalContributions += chartRawData[i].contributions;
chartData[i] = { date: new Date(chartRawData[i].timestamp * 1000), count: chartRawData[i].contributions };
chartData[i] = {date: new Date(chartRawData[i].timestamp * 1000), count: chartRawData[i].contributions};
}
self.values = chartData;
self.isLoading = false;
Expand Down
Loading

0 comments on commit e03d627

Please sign in to comment.