Skip to content

Commit

Permalink
chore: lint tests & projects and add eslint-plugin-import (gridsome#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo authored and hjvedvik committed Jun 3, 2019
1 parent 025ab83 commit cecc274
Show file tree
Hide file tree
Showing 21 changed files with 132 additions and 33 deletions.
2 changes: 0 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
__fixtures__
node_modules
projects
dist
16 changes: 10 additions & 6 deletions gridsome/app/.eslintrc.js → gridsome/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ module.exports = {
root: true,
extends: [
'eslint:recommended',
'plugin:vue/recommended'
'plugin:vue/recommended',
'plugin:import/errors',
'plugin:import/warnings'
],
parserOptions: {
parser: 'babel-eslint',
sourceType: 'module',
allowImportExportEverywhere: true
},
globals: {
global: true,
process: true,
require: true
env: {
jest: true,
node: true
},
rules: {
'quotes': ['error', 'single', { allowTemplateLiterals: true }],
'comma-dangle': ['error', 'never'],
'semi': ['error', 'never']
'semi': ['error', 'never'],
'no-console': 'off',
// Allow unresolved imports
'import/no-unresolved': 'off',
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import TestClass from './test-class'
import Layout from './layouts/Default.vue'

import './styles/main.css'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Layout from './layouts/Default.vue'

export default function (Vue, { head }) {
export default function (Vue) {
Vue.component('Layout', Layout)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Layout from './layouts/Default.vue'

export default function (Vue, { head }) {
export default function (Vue) {
Vue.component('Layout', Layout)
}
2 changes: 1 addition & 1 deletion gridsome/lib/app/ComponentParser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ComponentParser {
constructor (app) {
constructor () {
this._cached = {}
this._parsers = []
}
Expand Down
8 changes: 4 additions & 4 deletions gridsome/lib/app/__tests__/ImageProcessQueue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ test('add custom attributes to markup', async () => {

expect(result.imageHTML).toMatch(/test-1/)
expect(result.imageHTML).toMatch(/test-2/)
expect(result.imageHTML).toMatch(/height=\"100\"/)
expect(result.imageHTML).toMatch(/alt=\"Alternative text\"/)
expect(result.imageHTML).toMatch(/height="100"/)
expect(result.imageHTML).toMatch(/alt="Alternative text"/)

expect(result.noscriptHTML).toMatch(/test-1/)
expect(result.noscriptHTML).toMatch(/test-2/)
expect(result.noscriptHTML).toMatch(/height=\"100\"/)
expect(result.noscriptHTML).toMatch(/alt=\"Alternative text\"/)
expect(result.noscriptHTML).toMatch(/height="100"/)
expect(result.noscriptHTML).toMatch(/alt="Alternative text"/)
})

test('respect config.maxImageWidth', async () => {
Expand Down
2 changes: 1 addition & 1 deletion gridsome/lib/app/codegen/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { NOT_FOUND_NAME, NOT_FOUND_PATH } = require('../../utils/constants')

function genConstants ({ config }) {
function genConstants () {
let code = ''

code += `export const NOT_FOUND_NAME = ${JSON.stringify(NOT_FOUND_NAME)}\n`
Expand Down
6 changes: 4 additions & 2 deletions gridsome/lib/app/loadConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const builtInPlugins = [
]

// TODO: use joi to define and validate config schema
module.exports = (context, options = {}, pkg = {}) => {
module.exports = (context, options = {}) => {
const env = resolveEnv(context)

Object.assign(process.env, env)
Expand Down Expand Up @@ -156,7 +156,9 @@ function resolvePkg (context) {
try {
const content = fs.readFileSync(pkgPath, 'utf-8')
pkg = Object.assign(pkg, JSON.parse(content))
} catch (err) {}
} catch (err) {
// continue regardless of error
}

if (
!Object.keys(pkg.dependencies).includes('gridsome') &&
Expand Down
2 changes: 1 addition & 1 deletion gridsome/lib/app/queue/FileProcessQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FileProcessQueue {
return asset
}

async preProcess (filePath, options) {
async preProcess (filePath) {
if (!await fs.exists(filePath)) {
throw new Error(`${filePath} was not found. `)
}
Expand Down
2 changes: 1 addition & 1 deletion gridsome/lib/app/queue/ImageProcessQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ImageProcessQueue {
return asset
}

asset.sets.forEach(({ filename, destPath, src, width }) => {
asset.sets.forEach(({ filename, destPath, width }) => {
if (!this._queue.has(destPath + asset.cacheKey)) {
this._queue.set(destPath + asset.cacheKey, {
options: { ...options, width },
Expand Down
2 changes: 1 addition & 1 deletion gridsome/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async function renderHTML (renderQueue, app) {
info(`Render HTML (${renderQueue.length} files) - ${timer(hirestime.S)}s`)
}

async function processFiles (files, { outDir }) {
async function processFiles (files) {
const timer = hirestime()
const totalFiles = files.queue.length

Expand Down
4 changes: 2 additions & 2 deletions gridsome/lib/graphql/createFilterTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function createFilterType (value, fieldName, typeName) {
}
})

case 'number':
case 'number': {
const numberType = toGraphQLType(value)

return new GraphQLInputObjectType({
Expand All @@ -126,7 +126,7 @@ function createFilterType (value, fieldName, typeName) {
between: { type: new GraphQLList(numberType), description: desc.between }
}
})

}
case 'object':
return createObjectFilter(value, fieldName, typeName)
}
Expand Down
2 changes: 1 addition & 1 deletion gridsome/lib/graphql/nodes/createConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module.exports = ({ contentType, nodeType, fields }) => {
type: connectionType,
args: connectionArgs,
description: `Connection to all ${nodeType.name} nodes`,
async resolve (_, { regex, filter, ...args }, { store }, info) {
async resolve (_, { regex, filter, ...args }, { store }) {
const { collection } = store.getContentType(nodeType.name)
const sort = createSortOptions(args)
const query = {}
Expand Down
2 changes: 1 addition & 1 deletion gridsome/lib/plugins/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function corePlugin (api, config) {
}
})

api.afterBuild(({ queue, config }) => {
api.afterBuild(({ config }) => {
const notFoundPath = path.join(config.outDir, '404', 'index.html')
const notFoundDest = path.join(config.outDir, '404.html')

Expand Down
2 changes: 1 addition & 1 deletion gridsome/lib/server/middlewares/graphql.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { print } = require('graphql')
const { createQueryVariables } = require('../../pages/utils')

module.exports = ({ store, pages, config }) => {
module.exports = ({ pages }) => {
return async function graphqlMiddleware (req, res, next) {
const { body = {}} = req

Expand Down
2 changes: 1 addition & 1 deletion gridsome/lib/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
BOOTSTRAP_PAGES: 'pages',
BOOTSTRAP_CODE: 'code',

internalRE: /^internal\:\/\//,
internalRE: /^internal:\/\//,
transformerRE: /(?:^@?gridsome[/-]|\/)transformer-([\w-]+)/,

NODE_FIELDS: ['$uid', '$loki', 'internal', 'id', '_id'],
Expand Down
2 changes: 1 addition & 1 deletion gridsome/lib/webpack/createBaseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ module.exports = (app, { isProd, isServer }) => {
}
}

function createEnv (projectConfig) {
function createEnv () {
const assetsUrl = forwardSlash(path.join(publicPath, assetsDir, '/'))
const dataUrl = forwardSlash(path.join(assetsUrl, 'data', '/'))

Expand Down
2 changes: 1 addition & 1 deletion gridsome/lib/webpack/modules/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function transformAttrValue (node, attr) {
}

function isStatic (value) {
return /^\"[^"]+\"$/.test(value)
return /^"[^"]+"$/.test(value)
}

function extractValue (value) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
"test:unit": "node scripts/test.js",
"test:e2e": "node scripts/test.js --e2e",
"changelog": "node scripts/changelog.js",
"lint": "eslint \"gridsome/**/*.js\" \"packages/**/*.js\""
"lint": "eslint \"@(gridsome|packages)/**/*.js\""
},
"devDependencies": {
"@lerna/conventional-commits": "^3.4.1",
"babel-eslint": "^10.0.1",
"cheerio": "^1.0.0-rc.2",
"conventional-changelog": "^2.0.3",
"eslint": "^5.2.0",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-vue": "^4.7.1",
"eslint-plugin-vue-libs": "^3.0.0",
Expand Down
Loading

0 comments on commit cecc274

Please sign in to comment.