Moved grunt-eslint to npm script executing eslint (#10474)

refs #9441

* Updated top-level ids to use const
* Removed one layer of indentation
* Added .eslintignore files for server and test tasks
* Added npm scripts for eslint
* Fixed lint command in w/ grunt
* Uninstalled grunt-eslint
* Added eslint config
This commit is contained in:
Fabien O'Carroll 2019-02-11 13:26:06 +01:00 committed by GitHub
parent 6e0409d6db
commit bdd57b36cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 600 additions and 631 deletions

2
.eslintignore Normal file
View File

@ -0,0 +1,2 @@
core/server/public/**/*.js
core/server/lib/members/static/auth/**/*.js

View File

@ -8,34 +8,32 @@
require('./core/server/overrides'); require('./core/server/overrides');
var config = require('./core/server/config'), const config = require('./core/server/config');
urlService = require('./core/server/services/url'), const urlService = require('./core/server/services/url');
_ = require('lodash'), const _ = require('lodash');
chalk = require('chalk'), const chalk = require('chalk');
fs = require('fs-extra'), const fs = require('fs-extra');
KnexMigrator = require('knex-migrator'), const KnexMigrator = require('knex-migrator');
knexMigrator = new KnexMigrator({ const knexMigrator = new KnexMigrator({
knexMigratorFilePath: config.get('paths:appRoot') knexMigratorFilePath: config.get('paths:appRoot')
}), });
path = require('path'), const path = require('path');
const escapeChar = process.platform.match(/^win/) ? '^' : '\\';
const cwd = process.cwd().replace(/( |\(|\))/g, escapeChar + '$1');
const buildDirectory = path.resolve(cwd, '.build');
const distDirectory = path.resolve(cwd, '.dist');
escapeChar = process.platform.match(/^win/) ? '^' : '\\', let hasBuiltClient = false;
cwd = process.cwd().replace(/( |\(|\))/g, escapeChar + '$1'), const logBuildingClient = function (grunt) {
buildDirectory = path.resolve(cwd, '.build'),
distDirectory = path.resolve(cwd, '.dist'),
hasBuiltClient = false,
logBuildingClient = function (grunt) {
if (!hasBuiltClient) { if (!hasBuiltClient) {
grunt.log.writeln('Building admin client... (can take ~1min)'); grunt.log.writeln('Building admin client... (can take ~1min)');
setTimeout(logBuildingClient, 5000, grunt); setTimeout(logBuildingClient, 5000, grunt);
} }
}, };
// ## Grunt configuration // ## Grunt configuration
const configureGrunt = function (grunt) {
configureGrunt = function (grunt) {
// #### Load all grunt tasks // #### Load all grunt tasks
// //
// Find all of the task which start with `grunt-` and load them, rather than explicitly declaring them all // Find all of the task which start with `grunt-` and load them, rather than explicitly declaring them all
@ -109,35 +107,6 @@ var config = require('./core/server/config'),
} }
}, },
// ### grunt-eslint
// Linting rules, run as part of `grunt validate`. See [grunt validate](#validate) and its subtasks for
// more information.
eslint: {
server: {
options: {
config: '.eslintrc.json'
},
src: [
'*.js',
'core/*.js',
'core/server/*.js',
'core/server/**/*.js',
'!core/server/public/**/*.js',
'!core/server/lib/members/static/auth/**/*.js'
]
},
test: {
options: {
config: './core/test/.eslintrc.json'
},
src: [
'core/test/*.js',
'core/test/**/*.js',
'!core/test/coverage/**'
]
}
},
// ### grunt-mocha-cli // ### grunt-mocha-cli
mochacli: { mochacli: {
options: { options: {
@ -238,6 +207,9 @@ var config = require('./core/server/config'),
// ### grunt-shell // ### grunt-shell
// Command line tools where it's easier to run a command directly than configure a grunt plugin // Command line tools where it's easier to run a command directly than configure a grunt plugin
shell: { shell: {
lint: {
command: 'yarn lint'
},
master: { master: {
command: function () { command: function () {
var upstream = grunt.option('upstream') || process.env.GHOST_UPSTREAM || 'upstream'; var upstream = grunt.option('upstream') || process.env.GHOST_UPSTREAM || 'upstream';
@ -498,7 +470,7 @@ var config = require('./core/server/config'),
// //
// `grunt lint` will run the linter // `grunt lint` will run the linter
grunt.registerTask('lint', 'Run the code style checks for server & tests', grunt.registerTask('lint', 'Run the code style checks for server & tests',
['eslint'] ['shell:lint']
); );
// ### test-setup *(utility)( // ### test-setup *(utility)(

1
core/test/.eslintignore Normal file
View File

@ -0,0 +1 @@
core/test/coverage/**

View File

@ -26,7 +26,9 @@
"test": "grunt validate --verbose", "test": "grunt validate --verbose",
"test:regression": "grunt test-regression --verbose", "test:regression": "grunt test-regression --verbose",
"setup": "yarn install && knex-migrator init && grunt symlink && grunt init || true", "setup": "yarn install && knex-migrator init && grunt symlink && grunt init || true",
"lint": "grunt lint", "lint:server": "eslint --ignore-path .eslintignore 'core/server/**/*.js' 'core/*.js' '*.js'",
"lint:test": "eslint -c core/test/.eslintrc.json --ignore-path core/test/.eslintignore 'core/test/**/*.js'",
"lint": "yarn lint:server && yarn lint:test",
"fixmodulenotdefined": "yarn cache clean && cd core/client && rm -rf node_modules tmp dist && yarn && cd ../../" "fixmodulenotdefined": "yarn cache clean && cd core/client && rm -rf node_modules tmp dist && yarn && cd ../../"
}, },
"engines": { "engines": {
@ -127,7 +129,6 @@
"grunt-contrib-uglify": "4.0.0", "grunt-contrib-uglify": "4.0.0",
"grunt-contrib-watch": "1.1.0", "grunt-contrib-watch": "1.1.0",
"grunt-cssnano": "2.1.0", "grunt-cssnano": "2.1.0",
"grunt-eslint": "21.0.0",
"grunt-express-server": "0.5.4", "grunt-express-server": "0.5.4",
"grunt-mocha-cli": "4.0.0", "grunt-mocha-cli": "4.0.0",
"grunt-mocha-istanbul": "5.0.2", "grunt-mocha-istanbul": "5.0.2",

View File

@ -1625,7 +1625,7 @@ eslint-visitor-keys@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#3f3180fb2e291017716acb4c9d6d5b5c34a6a81d" resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#3f3180fb2e291017716acb4c9d6d5b5c34a6a81d"
eslint@5.12.1, eslint@^5.0.0: eslint@5.12.1:
version "5.12.1" version "5.12.1"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-5.12.1.tgz#5ca9931fb9029d04e7be92b03ce3b58edfac7e3b" resolved "https://registry.yarnpkg.com/eslint/-/eslint-5.12.1.tgz#5ca9931fb9029d04e7be92b03ce3b58edfac7e3b"
dependencies: dependencies:
@ -2565,13 +2565,6 @@ grunt-cssnano@2.1.0:
dependencies: dependencies:
cssnano "^3.0.0" cssnano "^3.0.0"
grunt-eslint@21.0.0:
version "21.0.0"
resolved "https://registry.yarnpkg.com/grunt-eslint/-/grunt-eslint-21.0.0.tgz#5863f593d328c27ffec2a183319e5ad5380eed9e"
dependencies:
chalk "^2.1.0"
eslint "^5.0.0"
grunt-express-server@0.5.4: grunt-express-server@0.5.4:
version "0.5.4" version "0.5.4"
resolved "https://registry.yarnpkg.com/grunt-express-server/-/grunt-express-server-0.5.4.tgz#8ce79c335c6cbb9ef50ee1dfaa61942028f43aeb" resolved "https://registry.yarnpkg.com/grunt-express-server/-/grunt-express-server-0.5.4.tgz#8ce79c335c6cbb9ef50ee1dfaa61942028f43aeb"