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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up linters #1225

Merged
merged 1 commit into from
Nov 1, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
last 2 Chrome versions
last 2 Edge versions
last 2 Firefox versions
last 2 Safari versions
54 changes: 54 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Linting

on:
push:
pull_request:

jobs:
cache-keys:
name: Setup – Cache keys
runs-on: ubuntu-latest

outputs:
build: build-${{ steps.build.outputs.hash }}-v2
dot-cache: dot-cache-${{ github.event.number }}-v1
node-modules: node-modules-${{ steps.node-modules.outputs.hash }}-v1

steps:
- name: Checkout
uses: actions/checkout@v4

- id: build
run: echo "::set-output name=hash::${{ hashFiles('assets/**', 'content/**', 'layouts/**', 'static/**', '**/package.json', '**/package-lock.json') }}"

- id: node-modules
run: echo "::set-output name=hash::${{ hashFiles('**/package-lock.json') }}"

test-lint:
name: Test – Lint
needs: cache-keys
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: '20'

- name: Get cached dependencies
uses: actions/cache@v4
with:
path: |
node_modules
key: ${{ needs.cache-keys.outputs.node-modules }}

- name: Check that package-lock.json is valid JSON
run: jq empty package-lock.json

- name: Install dependencies
run: npm ci

- name: Run linters
run: npm run lint
21 changes: 21 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Prettier

on:
push:
pull_request:

jobs:
prettier:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Prettify code
uses: creyD/[email protected]
with:
dry: True
prettier_options: --check assets/js/**
36 changes: 36 additions & 0 deletions .precious.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[commands.lint-scripts]
type = "lint"
cmd = [
"npm",
"run",
"lint:scripts"
]
invoke = "once"
include = ["assets/js/**/*.{ts}"]
ok-exit-codes = 0

[commands.stylelint-styles]
type="both"
cmd = [
"npx",
"stylelint"
]
lint-flags = []
tidy-flags = ["--fix"]
path-args = "absolute-file"
include = ["assets/scss/**"]
ok-exit-codes = 0

[commands.prettier-scripts]
type = "both"
cmd = [
"npx",
"prettier",
"--write"
]
lint-flags = ["--check"]
tidy-flags = ["--write"]
path-args = "absolute-file"
include = ["assets/js/**"]
ok-exit-codes = 0

160 changes: 160 additions & 0 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/* eslint-disable @typescript-eslint/no-require-imports */
const path = require('path');

module.exports = {
configBasedir: path.resolve(__dirname),
defaultSeverity: 'error',
extends: [
'stylelint-config-recommended',
'stylelint-config-sass-guidelines',
],
plugins: [
'stylelint-no-unsupported-browser-features',
'stylelint-order',
],
rules: {
'max-nesting-depth': 4,
'order/order': [
'custom-properties',
'declarations',
],
'order/properties-alphabetical-order': true,
'plugin/no-unsupported-browser-features': [
true,
{
ignore: [
/**
* Partial support - IE11
*
* Partial support in IE11 refers to calc not working properly
* with various use cases mentioned in known issues
*
* https://caniuse.com/calc
*/
'calc',

/**
* Not supported - IE 11
* Partial support - Safari
*
* https://caniuse.com/?search=appearance
*/
'css-appearance',

/**
* Not supported - IE11
*
* https://caniuse.com/?search=css-featurequeries
*/
'css-featurequeries',

/**
* Not supported - IE11
*
* https://caniuse.com/?search=css%20filters
*/
'css-filters',

/**
* Partial support - Safari
*
* Partial support in Safari and Older Firefox versions refers to
* not using premultiplied colors which results in unexpected
* behavior when using the transparent keyword as advised by the
* spec.
*
* https://caniuse.com/?search=css-gradients
*/
'css-gradients',

/**
* Not supported - IE11
*
* https://caniuse.com/?search=css-initial-value
*/
'css-initial-value',

/**
* Not supported - IE11
*
* Partial support - Chromium
*
* Supported on th elements, but not thead or tr
*
* Partial support - Firefox
*
* Not supported on any table parts
*
* https://caniuse.com/?search=css-sticky
*/
'css-sticky',

/**
* Partial support - IE11
*
* Partial support is due to large amount of bugs present.
*
* https://caniuse.com/?search=flexbox
*/
'flexbox',

/**
* Partial support - Chromium, Firefox
*
* Partial support refers to not supporting the avoid-column,
* column, and avoid (in the column context) values for the
* properties break-before, break-after, and break-inside.
*
* https://caniuse.com/?search=multicolumn
*/
'multicolumn',

/**
* Partial support - IE11
*
* Supports the value of invert for outline-color.
* Does not support outline-offset.
*
* https://caniuse.com/?search=outline
*/
'outline',

/**
* Partial support - IE11
*
* Partial support in IE refers to not supporting the
* `transform-style: preserve-3d` property. This prevents nesting 3D
* transformed elements.
*
* https://caniuse.com/?search=transforms3d
*/
'transforms3d',

/**
* Partial support - IE11
*
* Partial support refers to not supporting the "vmax" unit.
*
* https://caniuse.com/viewport-units
*/
'viewport-units',
],
},
],
'selector-class-pattern': [
'[a-z]([a-zA-Z0-9]+)?$',
{
resolveNestedSelectors: true,
},
],
'selector-max-compound-selectors': 5,
'selector-pseudo-class-no-unknown': [
true,
{
ignorePseudoClasses: [
'global',
],
},
],
},
};
56 changes: 35 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3 align="center">
<h1 align="center">
<img
alt="MaxMind"
src="assets/maxmind-logo.svg"
Expand All @@ -7,9 +7,9 @@
<br>
<br>
<small>Developer Documentation Static Site Generator</small>
</h3>
</h1>

* * *
---

## Overview

Expand All @@ -23,16 +23,15 @@
- [Installation](#installation)
- [Development](#development)
- [Development Server](#development-server)
- [Static Server](#static-server)
- [Testing](#testing)
- [Deployments](#deployments)
- [Updating Release Notes for the New Year](#updating-release-notes-for-the-new-year)

### Minimum Requirements

The minimum Node and NPM versions can be found in the [package.json file](package.json) under `engines`.
The minimum Node and NPM versions can be found in the
[package.json file](package.json) under `engines`.

If you need help installing and/or managing Node and NPM versions, check out [NVM](https://github.com/nvm-sh/nvm).
If you need help installing and/or managing Node and NPM versions, check out
[NVM](https://github.com/nvm-sh/nvm).

### Installation

Expand All @@ -42,6 +41,12 @@ npm install

- `npm install` installs the necessary node modules for development.

#### Install Precious

You should install our pre-commit hook. You can do this from your checkout
by running `git/setup.sh`. These hooks do things like ensure that the code you
commit is tidy and passes various linter checks.

#### Install Hugo

##### Homebrew (macOS)
Expand Down Expand Up @@ -86,15 +91,18 @@ Whenever you create your first release note for a product category for a new
year:

1. Add a file called `<year>.md` to the `/content/<product>/release-notes`
folder. (e.g., `/content/geoip/release-notes/2024.md`)
- Add the header to your new release note file with the title: `<Product> Release Notes`
(e.g., `GeoIP2 Release Notes`) and draft to `false`.
- Add the RSS notification to the top of the new file.
2. Change the `title:` field in the previous year's `md` file to read: `<Product> Release Notes - <Year> Archive`
(e.g., `GeoIP2 Release Notes - 2023 Archive`)
- Remove the RSS notification from the top of the archived file.
3. Update link to the release notes in the navigation menu (`hugo.toml`) to point to the current year's path.
4. Update the URLs in the redirects file (`static/_redirects`) to the current year's path.
folder. (e.g., `/content/geoip/release-notes/2024.md`) - Add the header to
your new release note file with the title: `<Product> Release Notes` (e.g.,
`GeoIP2 Release Notes`) and draft to `false`. - Add the RSS notification to
the top of the new file.
2. Change the `title:` field in the previous year's `md` file to read:
`<Product> Release Notes - <Year> Archive` (e.g.,
`GeoIP2 Release Notes - 2023 Archive`) - Remove the RSS notification from the
top of the archived file.
3. Update link to the release notes in the navigation menu (`hugo.toml`) to
point to the current year's path.
4. Update the URLs in the redirects file (`static/_redirects`) to the current
year's path.

### Updating Example CSVs

Expand All @@ -104,8 +112,11 @@ internal oneoffs repository.
### Adding Page Metadata for SEO and Social Sharing

#### Adding a description
In the markdown (mdx) file, add a `description` to the frontmatter located at the top of the file:
```

In the markdown (mdx) file, add a `description` to the frontmatter located at
the top of the file:

```md
---
draft: false
title: GeoIP2 is the best
Expand All @@ -117,9 +128,12 @@ description: GeoIP2 is the bestest IP Intelligence product suite ever made

1. Add your image to the [static/images](static/images) directory.

2. In the markdown (mdx) file, add the path to the `image` key in the frontmatter located at the top of the file. **Do not include `static` to the path.** For example, if your file is at `static/images/geoip2-so-cool.gif`, your frontmatter would look like:
2. In the markdown (mdx) file, add the path to the `image` key in the
frontmatter located at the top of the file. **Do not include `static` to the
path.** For example, if your file is at `static/images/geoip2-so-cool.gif`,
your frontmatter would look like:

```
```md
---
draft: false
title: GeoIP2 is the best
Expand Down
Loading
Loading