Skip to content

Commit

Permalink
chore(test): add code formatting and linting tests
Browse files Browse the repository at this point in the history
* chore(prettier): fix /drupal path in .prettierignore
* test: add code formatting and linting tests
* chore(test): use Drupal code formatting standards in modules
* chore(prettier): fix prettier formatting issues
* chore(eslint): fix eslint issues
* fix(www): fix TypeScript error
* chore(prettier): upgrade prettier to v3

Fixes #573
  • Loading branch information
JohnAlbin authored Nov 3, 2023
1 parent 83cab9d commit 1be6184
Show file tree
Hide file tree
Showing 47 changed files with 975 additions and 615 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ dist
public
node_modules
*.esm.js
drupal
/drupal
5 changes: 5 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"node": true,
"jest": true
},
"globals": {
"Drupal": true,
"drupalSettings": true,
"jQuery": true
},
"rules": {
"react/prop-types": 0,
"prettier/prettier": ["error"],
Expand Down
5 changes: 3 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
This pull request is for: (mark with an "x")

- [ ] `examples/*`
- [ ] `modules/next`
- [ ] `packages/next-drupal`
Expand All @@ -11,8 +12,8 @@ _Please add a link to the GitHub issue
where this problem is discussed._

- [ ] I need help adding tests. (mark with an "x")
_Code changes need test coverage. If you don't know
how to make tests, check this box to ask for help._
_Code changes need test coverage. If you don't know
how to make tests, check this box to ask for help._

## Describe your changes

Expand Down
2 changes: 1 addition & 1 deletion .github/version-pr/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ outputs:
version:
description: "npm package version"
runs:
using: "node16"
using: node20
main: "index.js"
2 changes: 1 addition & 1 deletion .github/workflows/release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
- name: Install dependencies
run: yarn install
- name: Determine version
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx pretty-quick --staged
npx lint-staged
3 changes: 3 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"*": "prettier --write"
}
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16
v18
34 changes: 23 additions & 11 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
cache
.cache
# Ignore everything.
/*

# Don't ignore some files in the root directory.
!/*.js
!/*.ts
!/*.md
!/*.json

# Don't ignore these nested directories.
!/examples
!/modules
!/packages
!/scripts
!/starters
!/test
!/www

# In any nested folder, ignore these paths:
.next
CHANGELOG.md
composer.json
dist
package.json
package-lock.json
public
CHANGELOG.md
.yarn
packages/codemod/transforms/__testfixtures__/**/*
packages/codemod/transforms/__tests__/**/*
packages/codemod/**/*.js
packages/codemod/**/*.d.ts
dist
.next
./drupal
15 changes: 11 additions & 4 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"endOfLine": "lf",
"semi": false,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5"
"trailingComma": "es5",
"overrides": [
{
"files": "modules/**/*",
"options": {
"semi": true,
"singleQuote": true,
"trailingComma": "all"
}
}
]
}
6 changes: 3 additions & 3 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ Refer to the table below for versions supported with security updates.
| Version | Supported |
| ------- | ------------------ |
| 1.x.x | :white_check_mark: |
| < 1.0.0 | :x: |
| < 1.0.0 | :x: |

### `next` Drupal module

| Version | Supported |
| ------- | ------------------ |
| 1.x.x | :white_check_mark: |
| < 1.0.0 | :x: |
| < 1.0.0 | :x: |

## Reporting a Vulnerability

If you believe you have found a security vulnerability in `next-drupal` package or the `next` Drupal module, we encourage you to let us know right away.

We will do our best to quickly fix the problem.
We will do our best to quickly fix the problem.

We will sync with the [Drupal Security Team](https://www.drupal.org/drupal-security-team) if the vulnerability affects the `next` Drupal module.

Expand Down
2 changes: 1 addition & 1 deletion examples/example-auth/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
import "./commands"

// Alternatively you can use CommonJS syntax:
// require('./commands')
2 changes: 1 addition & 1 deletion examples/example-auth/types/next-auth.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DefaultSession, Session } from "next-auth"
import { DefaultSession } from "next-auth"

declare module "next-auth" {
interface Session {
Expand Down
28 changes: 6 additions & 22 deletions examples/example-blog/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
Expand All @@ -19,24 +15,12 @@
"jsx": "preserve",
"baseUrl": "./",
"paths": {
"@/components/*": [
"src/components/*"
],
"@utils/*": [
"src/utils/*"
],
"@/config": [
"src/config"
]
"@/components/*": ["src/components/*"],
"@utils/*": ["src/utils/*"],
"@/config": ["src/config"]
},
"incremental": true
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion examples/example-custom-cache/lib/drupal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Experiment_DrupalClient, DataCache } from "next-drupal"
import { DataCache, DrupalClient } from "next-drupal"
import Redis from "ioredis"

const redis = new Redis(process.env.REDIS_URL)
Expand Down
2 changes: 1 addition & 1 deletion examples/example-marketing/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
import "./commands"

// Alternatively you can use CommonJS syntax:
// require('./commands')
6 changes: 5 additions & 1 deletion examples/example-marketing/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as React from "react"
import Router from "next/router"
import { QueryClient, QueryClientProvider, Hydrate } from "@tanstack/react-query"
import {
QueryClient,
QueryClientProvider,
Hydrate,
} from "@tanstack/react-query"
import NProgress from "nprogress"
import { syncDrupalPreviewRoutes } from "next-drupal"
import "nprogress/nprogress.css"
Expand Down
2 changes: 1 addition & 1 deletion examples/example-query/pages/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function getStaticProps(context) {
}
}

const type = path.jsonapi.resourceName as typeof RESOURCE_TYPES[number]
const type = path.jsonapi.resourceName as (typeof RESOURCE_TYPES)[number]

if (!RESOURCE_TYPES.includes(type)) {
return {
Expand Down
2 changes: 1 addition & 1 deletion examples/example-query/types/drupal/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface FieldTextFormatted {

export type FieldEntityReference<
Types,
Cardinality extends FieldCardinality = "limited"
Cardinality extends FieldCardinality = "limited",
> = Cardinality extends "unlimited" ? Array<Partial<Types>> : Partial<Types>

export type FieldList<List> = keyof List
2 changes: 1 addition & 1 deletion examples/example-search-api/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
import "./commands"

// Alternatively you can use CommonJS syntax:
// require('./commands')
4 changes: 1 addition & 3 deletions examples/example-umami/components/meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export function Meta({ title, description }: MetaProps) {
rel="canonical"
href={absoluteURL(router.asPath !== "/" ? router.asPath : "")}
/>
<title>
{`${title} | ${siteConfig.name}`}
</title>
<title>{`${title} | ${siteConfig.name}`}</title>
<meta name="description" content={description || siteConfig.slogan} />
<meta
property="og:image"
Expand Down
6 changes: 5 additions & 1 deletion examples/example-umami/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import * as React from "react"
import Router from "next/router"
import { SessionProvider } from "next-auth/react"
import { QueryClient, QueryClientProvider, Hydrate } from "@tanstack/react-query"
import {
QueryClient,
QueryClientProvider,
Hydrate,
} from "@tanstack/react-query"
import { appWithTranslation } from "next-i18next"
import NProgress from "nprogress"
import "nprogress/nprogress.css"
Expand Down
2 changes: 1 addition & 1 deletion examples/example-webform/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
import "./commands"

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading

1 comment on commit 1be6184

@vercel
Copy link

@vercel vercel bot commented on 1be6184 Nov 3, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.