Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ESLint config for JavaScript Standard Style #2849

Merged
merged 4 commits into from Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,21 @@
module.exports = {
extends: 'standard',
ignorePatterns: [
domoscargin marked this conversation as resolved.
Show resolved Hide resolved
'!.*',
'dist/**/*',
'node_modules',
'node_modules/.*',
Comment on lines +6 to +7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is unnnecessary as ESLint already ignores node_modules (buried in this page of their doc):

In addition to any patterns in the .eslintignore file, ESLint always follows a couple of implicit ignore rules even if the --no-ignore flag is passed. The implicit rules are as follows:

  • node_modules/ is ignored.
  • dot-files (except for .eslintrc.*), as well as dot-folders and their contents, are ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh sorry, I should explain

See a bit further up I've added '!.*'?

It's to override ESLint's "ignore dot-files by default" logic so we can lint files such as:

.eslintrc.js
.lintstagedrc.js
.babelrc.js

But then sadly it seems to then include "dot files inside node_modules" which made this combo necessary:

'node_modules',
'node_modules/.*',

Glad you spotted it though, I love a good code review 馃槉

'package-lock.json',
'package/**/*',
'public/**/*',
'src/govuk/vendor/polyfills/**/*'
],
overrides: [
{
files: ['**/*.test.{cjs,js,mjs}'],
env: {
jest: true
}
}
]
}
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,3 +9,4 @@ package/package-lock.json
examples/**/package-lock.json
*.zip
sassdoc/
.cache
2 changes: 1 addition & 1 deletion app/app.js
Expand Up @@ -114,7 +114,7 @@ module.exports = (options) => {
res.render('index', {
componentsDirectory: components,
examplesDirectory: examples,
fullPageExamples: fullPageExamples
fullPageExamples
})
})

Expand Down
2 changes: 0 additions & 2 deletions app/app.test.js
@@ -1,5 +1,3 @@
/* eslint-env jest */

const request = require('request')
const cheerio = require('cheerio')

Expand Down
2 changes: 0 additions & 2 deletions app/banner.test.js
@@ -1,5 +1,3 @@
/* eslint-env jest */

const request = require('request')
const cheerio = require('cheerio')

Expand Down
2 changes: 0 additions & 2 deletions app/full-page-examples.test.js
@@ -1,5 +1,3 @@
/* eslint-env jest */

const request = require('request')
const cheerio = require('cheerio')

Expand Down
12 changes: 6 additions & 6 deletions config/paths.json
@@ -1,18 +1,18 @@
{
"app": "app/",
"views": "app/views/",
"examples": "app/views/examples/",
"fullPageExamples": "app/views/full-page-examples/",
"partials": "app/views/partials/",
"layouts": "app/views/layouts/",
"views": "app/views/",
"examples": "app/views/examples/",
"fullPageExamples": "app/views/full-page-examples/",
"partials": "app/views/partials/",
"layouts": "app/views/layouts/",
"config": "config/",
"dist": "dist/",
"node_modules": "node_modules/",
"package": "package/",
"public": "public/",
"sassdoc": "sassdoc/",
"src": "src/govuk/",
"components": "src/govuk/components/",
"components": "src/govuk/components/",
"ports": {
"app": 3000,
"test": 8888
Expand Down
2 changes: 0 additions & 2 deletions gulpfile.js
@@ -1,5 +1,3 @@
'use strict'

const paths = require('./config/paths.json')
const gulp = require('gulp')
const taskListing = require('gulp-task-listing')
Expand Down
11 changes: 11 additions & 0 deletions lib/.eslintrc.js
@@ -0,0 +1,11 @@
module.exports = {
overrides: [
{
files: ['jest-*'],
domoscargin marked this conversation as resolved.
Show resolved Hide resolved
globals: {
page: true,
browser: true
}
}
]
}
2 changes: 0 additions & 2 deletions lib/file-helper.js
@@ -1,5 +1,3 @@
'use strict'

const fs = require('fs')
const path = require('path')
const yaml = require('js-yaml')
Expand Down
10 changes: 4 additions & 6 deletions lib/file-helper.unit.test.js
@@ -1,5 +1,3 @@
/* eslint-env jest */

const path = require('path')
const fileHelper = require('../lib/file-helper')

Expand All @@ -17,7 +15,7 @@ describe('getComponentData', () => {
})

it('outputs objects with an array of params and examples', () => {
var componentData = fileHelper.getComponentData('accordion')
const componentData = fileHelper.getComponentData('accordion')

expect(componentData).toEqual(expect.objectContaining({
params: expect.any(Array),
Expand All @@ -26,7 +24,7 @@ describe('getComponentData', () => {
})

it('outputs a param for each object with the expected attributes', () => {
var componentData = fileHelper.getComponentData('accordion')
const componentData = fileHelper.getComponentData('accordion')

componentData.params.forEach((param) => {
expect(param).toEqual(
Expand All @@ -41,7 +39,7 @@ describe('getComponentData', () => {
})

it('contains example objects with the expected attributes', () => {
var componentData = fileHelper.getComponentData('accordion')
const componentData = fileHelper.getComponentData('accordion')

componentData.examples.forEach((example) => {
expect(example).toEqual(
Expand All @@ -56,7 +54,7 @@ describe('getComponentData', () => {

describe('fullPageExamples', () => {
it('contains name and path of each example, at a minimum', () => {
var fullPageExamples = fileHelper.fullPageExamples()
const fullPageExamples = fileHelper.fullPageExamples()

fullPageExamples.forEach((example) => {
expect(example).toEqual(
Expand Down
2 changes: 0 additions & 2 deletions lib/helper-functions.js
@@ -1,5 +1,3 @@
'use strict'

/**
* Convert a kebab-cased string to a PascalCased one
*
Expand Down
2 changes: 0 additions & 2 deletions lib/helper-functions.unit.test.js
@@ -1,5 +1,3 @@
/* eslint-env jest */

const helpers = require('../lib/helper-functions')

describe('componentNameToJavaScriptClassName', () => {
Expand Down
18 changes: 14 additions & 4 deletions lib/jest-helpers.js
@@ -1,5 +1,3 @@
'use strict'

const fs = require('fs')
const path = require('path')
const util = require('util')
Expand All @@ -8,6 +6,7 @@ const cheerio = require('cheerio')
const nunjucks = require('nunjucks')
const outdent = require('outdent')
const yaml = require('js-yaml')
const { configureAxe } = require('jest-axe')

const sass = require('node-sass')
const sassRender = util.promisify(sass.render)
Expand Down Expand Up @@ -118,7 +117,7 @@ async function renderAndInitialise (componentName, options = {}) {
}, html)

const initialiser = options.initialiser || function ({ config, componentClassName }) {
var $component = document.querySelector('[data-module]')
const $component = document.querySelector('[data-module]')
new window.GOVUKFrontend[componentClassName]($component, config).init()
}

Expand Down Expand Up @@ -184,4 +183,15 @@ function htmlWithClassName ($, className) {
return $.html($component)
}

module.exports = { render, renderHtml, renderAndInitialise, getExamples, htmlWithClassName, renderSass, renderTemplate }
/**
* As we're testing incomplete HTML fragments, we don't expect there to be a
* skip link, or for them to be contained within landmarks.
*/
const axe = configureAxe({
rules: {
'skip-link': { enabled: false },
region: { enabled: false }
}
})

module.exports = { axe, render, renderHtml, renderAndInitialise, getExamples, htmlWithClassName, renderSass, renderTemplate }