提交 c1f748f3 编写于 作者: A azakrzewski

Merge pull request #25 from kubernetes/eslint

Wire ESlint with the project and fix its errors
......@@ -10,10 +10,17 @@
"extends": "eslint:recommended",
"env": {
// Enables all ES6 features except modules.
"es6": true
"es6": true,
},
"ecmaFeatures": {
// Enable ES6 modules to have all language features covered.
"modules": true
}
"modules": true,
},
"rules": {
// Require dangling comma at the end of any multiline list/object. This is to be consistent
// with backend code.
"comma-dangle": [2, "always-multiline"],
// No spacing in object literals nor in imports/exports.
"object-curly-spacing": [2, "never"],
},
}
......@@ -2,5 +2,9 @@
"env": {
// Build files are written in node.
"node": true
},
"rules": {
// This folder contains Node code, so using console is fine.
"no-console": 0
}
}
......@@ -31,7 +31,7 @@ import conf from './conf';
*/
const goBackendDependencies = [
'github.com/golang/glog',
'github.com/spf13/pflag'
'github.com/spf13/pflag',
];
......@@ -45,7 +45,7 @@ const goBackendDependencies = [
*/
function spawnGoProcess(args, doneFn, opt_env) {
var goTask = child.spawn('go', args, {
env: lodash.merge(process.env, {GOPATH: conf.paths.backendTmp}, opt_env || {})
env: lodash.merge(process.env, {GOPATH: conf.paths.backendTmp}, opt_env || {}),
});
// Call Gulp callback on task exit. This has to be done to make Gulp dependency management
......@@ -76,7 +76,7 @@ gulp.task('backend', ['backend-dependencies'], function(doneFn) {
spawnGoProcess([
'build',
'-o', path.join(conf.paths.serve, 'console'),
path.join(conf.paths.backendSrc, 'console.go')
path.join(conf.paths.backendSrc, 'console.go'),
], doneFn);
});
......@@ -98,12 +98,12 @@ gulp.task('backend:prod', ['backend-dependencies'], function(doneFn) {
'-a',
'-installsuffix', 'cgo',
'-o', outputBinaryPath,
path.join(conf.paths.backendSrc, 'console.go')
path.join(conf.paths.backendSrc, 'console.go'),
], doneFn, {
// Disable cgo package. Required to run on scratch docker image.
CGO_ENABLED: '0',
// Scratch docker image is linux.
GOOS: 'linux'
GOOS: 'linux',
});
}, function(error) {
doneFn(error);
......
......@@ -17,9 +17,7 @@
*/
import del from 'del';
import gulp from 'gulp';
import gulpEslint from 'gulp-eslint';
import gulpFilter from 'gulp-filter';
import gulpInject from 'gulp-inject';
import gulpMinifyCss from 'gulp-minify-css';
import gulpMinifyHtml from 'gulp-minify-html';
import gulpUglify from 'gulp-uglify';
......@@ -27,7 +25,6 @@ import gulpUseref from 'gulp-useref';
import gulpRev from 'gulp-rev';
import gulpRevReplace from 'gulp-rev-replace';
import gulpSize from 'gulp-size';
import gulpSourcemaps from 'gulp-sourcemaps';
import uglifySaveLicense from 'uglify-save-license';
import path from 'path';
......@@ -55,8 +52,8 @@ gulp.task('build', ['index:prod', 'assets'], function () {
// To resolve local paths.
conf.paths.prodTmp,
// To resolve bower_components/... paths.
conf.paths.base
]
conf.paths.base,
],
}))
.pipe(vendorCssFilter)
.pipe(gulpMinifyCss())
......@@ -72,7 +69,7 @@ gulp.task('build', ['index:prod', 'assets'], function () {
.pipe(gulpMinifyHtml({
empty: true,
spare: true,
quotes: true
quotes: true,
}))
.pipe(htmlFilter.restore)
.pipe(gulp.dest(conf.paths.dist))
......
......@@ -28,6 +28,16 @@ const basePath = path.join(__dirname, '../');
* Exported configuration object with common constants used in build pipeline.
*/
export default {
/**
* Frontend application constants.
*/
frontend: {
/**
* The name of the root Angular module, i.e., the module that bootstraps the application.
*/
rootModuleName: 'kubernetesConsole',
},
/**
* Absolute paths to known directories, e.g., to source directory.
*/
......@@ -39,6 +49,7 @@ export default {
backendTmp: path.join(basePath, '.tmp/backend'),
bowerComponents: path.join(basePath, 'bower_components'),
build: path.join(basePath, 'build'),
deploySrc: path.join(basePath, 'src/app/deploy'),
dist: path.join(basePath, 'dist'),
externs: path.join(basePath, 'src/app/externs'),
frontendSrc: path.join(basePath, 'src/app/frontend'),
......@@ -51,16 +62,6 @@ export default {
protractorConf: path.join(basePath, 'build/protractor.conf.js'),
serve: path.join(basePath, '.tmp/serve'),
src: path.join(basePath, 'src'),
tmp: path.join(basePath, '.tmp')
tmp: path.join(basePath, '.tmp'),
},
/**
* Frontend application constants.
*/
frontend: {
/**
* The name of the root Angular module, i.e., the module that bootstraps the application.
*/
rootModuleName: 'kubernetesConsole'
}
};
......@@ -30,20 +30,20 @@ import conf from './conf';
* @param {string} indexPath
*/
function createIndexFile(indexPath) {
let injectStyles = gulp.src(path.join(indexPath, '**/*.css'), { read: false });
let injectStyles = gulp.src(path.join(indexPath, '**/*.css'), {read: false});
let injectScripts = gulp.src(path.join(indexPath, '**/*.js'), { read: false });
let injectScripts = gulp.src(path.join(indexPath, '**/*.js'), {read: false});
let injectOptions = {
// Make the dependencies relative to the deps directory.
ignorePath: [path.relative(conf.paths.base, indexPath)],
addRootSlash: false,
quiet: true
quiet: true,
};
let wiredepOptions = {
// Make wiredep dependencies begin with "bower_components/" not "../../...".
ignorePath: path.relative(conf.paths.frontendSrc, indexPath) + '/'
ignorePath: path.relative(conf.paths.frontendSrc, indexPath) + '/',
};
return gulp.src(path.join(conf.paths.frontendSrc, 'index.html'))
......
......@@ -33,14 +33,14 @@ function getFileList() {
// All app dependencies are required for tests. Include them.
let wiredepOptions = {
dependencies: true,
devDependencies: true
devDependencies: true,
};
return wiredep(wiredepOptions).js
.concat([
path.join(conf.paths.frontendTest, '**/*.js'),
path.join(conf.paths.frontendSrc, '**/*.js'),
path.join(conf.paths.frontendSrc, '**/*.html')
path.join(conf.paths.frontendSrc, '**/*.html'),
]);
}
......@@ -71,7 +71,7 @@ export default function(config) {
'karma-jasmine',
'karma-ng-html2js-preprocessor',
'karma-sourcemap-loader',
'karma-browserify'
'karma-browserify',
],
// karma-browserify plugin config.
......@@ -82,15 +82,15 @@ export default function(config) {
paths: [conf.paths.frontendSrc, conf.paths.frontendTest],
transform: [
// Transform ES6 code into ES5 so that browsers can digest it.
'babelify'
]
'babelify',
],
},
// karma-ng-html2js-preprocessor plugin config.
ngHtml2JsPreprocessor: {
stripPrefix: conf.paths.frontendSrc + '/',
moduleName: conf.frontend.moduleName
}
moduleName: conf.frontend.moduleName,
},
};
// Convert all JS code written ES6 with modules to ES5 bundles that browsers can digest.
......
......@@ -29,10 +29,10 @@ var path = require('path');
*/
exports.config = {
capabilities: {
'browserName': 'chrome'
'browserName': 'chrome',
},
baseUrl: 'http://localhost:3000',
specs: [path.join(conf.paths.integrationTest, '**/*.js')]
specs: [path.join(conf.paths.integrationTest, '**/*.js')],
};
......@@ -18,6 +18,7 @@
import gulp from 'gulp';
import gulpAngularTemplatecache from 'gulp-angular-templatecache';
import gulpClosureCompiler from 'gulp-closure-compiler';
import gulpEslint from 'gulp-eslint';
import gulpMinifyHtml from 'gulp-minify-html';
import lodash from 'lodash';
import path from 'path';
......@@ -38,11 +39,11 @@ const closureCompilerBaseConfig = {
js_module_root: conf.paths.frontendSrc,
language_in: 'ECMASCRIPT6_STRICT',
language_out: 'ECMASCRIPT3',
manage_closure_dependencies: true
manage_closure_dependencies: true,
},
compilerPath: path.join(conf.paths.nodeModules, 'google-closure-compiler/compiler.jar'),
// This makes the compiler faster. Requires Java 7+.
tieredCompilation: true
tieredCompilation: true,
};
......@@ -66,8 +67,8 @@ gulp.task('scripts', ['create-serve-folders'], function() {
// Make source map URLs relative to frontend source directory.
source_map_location_mapping: path.relative(conf.paths.base, conf.paths.frontendSrc) + '|',
// Include source map in the output bundle.
output_wrapper: '%output%\n//# sourceMappingURL=' + `${bundleBaseName}.js.map`
}
output_wrapper: '%output%\n//# sourceMappingURL=' + `${bundleBaseName}.js.map`,
},
}, closureCompilerBaseConfig);
return gulp.src(path.join(conf.paths.frontendSrc, '**/*.js'))
......@@ -81,8 +82,6 @@ gulp.task('scripts', ['create-serve-folders'], function() {
* directory.
*/
gulp.task('scripts:prod', ['angular-templates'], function() {
let bundleBaseName = 'app';
let closureCompilerConfig = lodash.merge({
fileName: 'app.js',
compilerFlags: {
......@@ -103,10 +102,10 @@ gulp.task('scripts', ['create-serve-folders'], function() {
// This check does not work correctly with ES6.
'inferredConstCheck',
// Let ESLint handle all lint checks.
'lintChecks'
'lintChecks',
],
use_types_for_optimization: null
}
use_types_for_optimization: null,
},
}, closureCompilerBaseConfig);
return gulp.src([
......@@ -116,7 +115,7 @@ gulp.task('scripts', ['create-serve-folders'], function() {
path.join(conf.paths.partials, '**/*.js'),
// Include base.js to enable some compiler functions, e.g., @export annotation handling.
path.join(conf.paths.bowerComponents,
'google-closure-library/closure/goog/base.js')
'google-closure-library/closure/goog/base.js'),
])
.pipe(gulpClosureCompiler(closureCompilerConfig))
.pipe(gulp.dest(conf.paths.prodTmp));
......@@ -131,10 +130,10 @@ gulp.task('angular-templates', function () {
.pipe(gulpMinifyHtml({
empty: true,
spare: true,
quotes: true
quotes: true,
}))
.pipe(gulpAngularTemplatecache('angular-templates.js', {
module: conf.frontend.rootModuleName
module: conf.frontend.rootModuleName,
}))
.pipe(gulp.dest(conf.paths.partials));
});
......
......@@ -31,15 +31,15 @@ import conf from './conf';
function browserSyncInit(baseDir) {
// Enable custom support for Angular apps, e.g., history management.
browserSync.use(browserSyncSpa({
selector: '[ng-app]'
selector: '[ng-app]',
}));
browserSync.instance = browserSync.init({
startPath: '/',
server: {
baseDir: baseDir
baseDir: baseDir,
},
browser: [] // Needed so that the browser does not auto-launch.
browser: [], // Needed so that the browser does not auto-launch.
});
}
......@@ -52,7 +52,7 @@ gulp.task('serve', ['watch'], function () {
conf.paths.serve,
conf.paths.frontendSrc, // For angular templates to work.
conf.paths.app, // For assets to work.
conf.paths.base // For bower dependencies to work.
conf.paths.base, // For bower dependencies to work.
]);
});
......@@ -72,7 +72,7 @@ gulp.task('watch', ['index'], function () {
gulp.watch([path.join(conf.paths.frontendSrc, 'index.html'), 'bower.json'], ['index']);
gulp.watch([
path.join(conf.paths.frontendSrc, '**/*.scss')
path.join(conf.paths.frontendSrc, '**/*.scss'),
], function(event) {
if(event.type === 'changed') {
// If this is a file change, rebuild only styles - nothing more is needed.
......
......@@ -34,15 +34,15 @@ import conf from './conf';
*/
gulp.task('styles', function () {
let sassOptions = {
style: 'expanded'
style: 'expanded',
};
let cssFilter = gulpFilter('**/*.css', { restore: true });
let cssFilter = gulpFilter('**/*.css', {restore: true});
return gulp.src(path.join(conf.paths.frontendSrc, '**/*.scss'))
.pipe(gulpSass(sassOptions))
.pipe(cssFilter)
.pipe(gulpSourcemaps.init({ loadMaps: true }))
.pipe(gulpSourcemaps.init({loadMaps: true}))
.pipe(gulpAutoprefixer())
.pipe(gulpSourcemaps.write())
.pipe(cssFilter.restore)
......@@ -58,7 +58,7 @@ gulp.task('styles', function () {
*/
gulp.task('styles:prod', function () {
let sassOptions = {
style: 'compressed'
style: 'compressed',
};
return gulp.src(path.join(conf.paths.frontendSrc, '**/*.scss'))
......
......@@ -32,7 +32,7 @@ function runUnitTests(singleRun, doneFn) {
let localConfig = {
configFile: conf.paths.karmaConf,
singleRun: singleRun,
autoWatch: !singleRun
autoWatch: !singleRun,
};
let server = new karma.Server(localConfig, function(failCount) {
......@@ -48,7 +48,7 @@ function runUnitTests(singleRun, doneFn) {
function runProtractorTests(doneFn) {
gulp.src(path.join(conf.paths.integrationTest, '**/*.js'))
.pipe(gulpProtractor.protractor({
configFile: conf.paths.protractorConf
configFile: conf.paths.protractorConf,
}))
.on('error', function (err) {
doneFn(err);
......
......@@ -3,6 +3,12 @@
"plugins": ["angular"],
"rules": {
// Disable undefined variable checking. This is done by the compiler.
"no-undef": 0
"no-undef": 0,
// Disable module getter rule. It gives no benefits in this codebase. Every file is
// in its own module, so there is no variable leaking.
"angular/module-getter": 0,
// Disable dependency injection linting because the linter does not understand
// @ngInject JsDoc annotation.
"angular/di": 0,
}
}
......@@ -16,10 +16,10 @@
* @fileoverview Entry point module to the application. Loads and configures other modules needed
* to bootstrap the application.
*/
import { config } from './index.config';
import { RouterController, routerConfig } from './index.route';
import { runBlock } from './index.run';
import { MainController } from './main/main.controller';
import {config} from './index.config';
import {RouterController, routerConfig} from './index.route';
import {runBlock} from './index.run';
import {MainController} from './main/main.controller';
export default angular.module(
'kubernetesConsole',
......
......@@ -31,7 +31,7 @@ export class RouterController {
*/
constructor($router) {
$router.config([
{ path: '/', component: 'main' }
{path: '/', component: 'main'},
]);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册