Skip to content
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
22 changes: 16 additions & 6 deletions .github/workflows/package-lock-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
run: |
npm --version

# Save the current top-level dependencies from package-lock.json
node -e "console.log(JSON.stringify(require('./package-lock.json').packages['']))" > /tmp/before.json

# From https://docs.npmjs.com/cli/v7/commands/npm-install
#
# The --package-lock-only argument will only update the
Expand All @@ -45,9 +48,16 @@ jobs:
#
npm install --package-lock-only --ignore-scripts --include=optional

# If the package.json (dependencies and devDependencies) is
# in correct sync with package-lock.json running the above command
# should *not* make an edit to the package-lock.json. I.e.
# running `git status` should
# say "nothing to commit, working tree clean".
git diff --exit-code
# Extract the top-level dependencies after regeneration
node -e "console.log(JSON.stringify(require('./package-lock.json').packages['']))" > /tmp/after.json

# Compare only the top-level package dependencies
# This ignores platform-specific differences in nested dependency resolution
# (like "peer" flags) that don't affect actual installed versions
if ! diff /tmp/before.json /tmp/after.json; then
echo "ERROR: Top-level dependencies in package-lock.json are out of sync with package.json"
echo "Please run 'npm install' locally and commit the updated package-lock.json"
exit 1
fi

echo "✓ Top-level dependencies are in sync"
4 changes: 3 additions & 1 deletion data/reusables/copilot/ccr-model-settings.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
> [!NOTE]
> {% data variables.copilot.copilot_code-review_short %} may use models that are not enabled on your organization's "Models" settings page. See [AUTOTITLE](/copilot/how-tos/administer-copilot/manage-for-organization/manage-policies).
> {% data variables.copilot.copilot_code-review_short %} may use models that are not enabled on your organization's "Models" settings page. The "Models" settings page only controls {% data variables.copilot.copilot_chat_short %}.
>
> Since {% data variables.copilot.copilot_code-review_short %} is generally available, all model usage will be subject to the generally available terms. See [AUTOTITLE](/copilot/how-tos/administer-copilot/manage-for-organization/manage-policies).
57 changes: 57 additions & 0 deletions eslint-plugins.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Type declarations for ESLint plugins without official TypeScript definitions

declare module 'eslint-plugin-github' {
import type { ESLint, Linter } from 'eslint'

const plugin: ESLint.Plugin & {
configs: {
recommended: Linter.FlatConfig
}
}

export default plugin
}

declare module 'eslint-plugin-primer-react' {
import type { ESLint, Linter } from 'eslint'

const plugin: ESLint.Plugin & {
configs: {
recommended: Linter.FlatConfig
}
}

export default plugin
}

declare module 'eslint-plugin-eslint-comments' {
import type { ESLint } from 'eslint'

const plugin: ESLint.Plugin

export default plugin
}

declare module 'eslint-plugin-i18n-text' {
import type { ESLint } from 'eslint'

const plugin: ESLint.Plugin

export default plugin
}

declare module 'eslint-plugin-filenames' {
import type { ESLint } from 'eslint'

const plugin: ESLint.Plugin

export default plugin
}

declare module 'eslint-plugin-no-only-tests' {
import type { ESLint } from 'eslint'

const plugin: ESLint.Plugin

export default plugin
}
83 changes: 0 additions & 83 deletions eslint.config.js → eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,89 +14,6 @@ import prettier from 'eslint-config-prettier'
import globals from 'globals'

export default [
// JavaScript and MJS files configuration
{
files: ['**/*.{js,mjs}'],
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
globals: {
...globals.browser,
...globals.node,
...globals.commonjs,
...globals.es2020,
},
parserOptions: {
requireConfigFile: false,
},
},
settings: {
'import/resolver': {
typescript: true,
node: true,
},
},
plugins: {
github,
import: importPlugin,
'eslint-comments': eslintComments,
'i18n-text': i18nText,
filenames,
'no-only-tests': noOnlyTests,
prettier: prettierPlugin,
},
rules: {
// ESLint recommended rules
...js.configs.recommended.rules,

// GitHub plugin recommended rules
...github.configs.recommended.rules,

// Import plugin error rules
...importPlugin.configs.errors.rules,

// JavaScript-specific overrides
'import/no-extraneous-dependencies': [
'error',
{
packageDir: '.',
},
],
'import/extensions': 'off',
'no-console': 'off',
camelcase: 'off',
'no-shadow': 'off',
'prefer-template': 'off',
'no-constant-condition': 'off',
'no-unused-vars': 'off',
'import/no-named-as-default-member': 'off',
'one-var': 'off',
'import/no-namespace': 'off',
'import/no-anonymous-default-export': 'off',
'object-shorthand': 'off',
'no-empty': 'off',
'prefer-const': 'off',
'import/no-named-as-default': 'off',
'no-useless-concat': 'off',
'func-style': 'off',

// Disable GitHub plugin rules that were disabled in original config
'github/array-foreach': 'off',
'github/no-then': 'off',

// Disable rules that might not exist or cause issues initially
'i18n-text/no-en': 'off',
'filenames/match-regex': 'off',
'eslint-comments/no-use': 'off',
'eslint-comments/no-unused-disable': 'off',
'eslint-comments/no-unlimited-disable': 'off',

// Disable new ESLint 9 rules that are causing issues
'no-constant-binary-expression': 'off',
},
},

// TypeScript and TSX files configuration
{
files: ['**/*.{ts,tsx}'],
languageOptions: {
Expand Down
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"@types/connect-timeout": "1.9.0",
"@types/cookie": "0.6.0",
"@types/cookie-parser": "1.4.8",
"@types/eslint-plugin-jsx-a11y": "^6.10.1",
"@types/event-to-promise": "^0.7.5",
"@types/express": "^5.0.3",
"@types/imurmurhash": "^0.1.4",
Expand Down Expand Up @@ -298,6 +299,7 @@
"graphql": "^16.9.0",
"http-status-code": "^2.1.0",
"husky": "^9.1.7",
"jiti": "^2.6.1",
"json-schema-merge-allof": "^0.8.1",
"lint-staged": "^16.0.0",
"markdownlint": "^0.34.0",
Expand Down
2 changes: 0 additions & 2 deletions src/ai-tools/scripts/ai-tools.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

import { fileURLToPath } from 'url'
import { Command } from 'commander'
import fs from 'fs'
Expand Down
89 changes: 89 additions & 0 deletions src/content-linter/lib/linting-rules/frontmatter-hero-image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import fs from 'fs'
import path from 'path'
// @ts-ignore - markdownlint-rule-helpers doesn't have TypeScript declarations
import { addError } from 'markdownlint-rule-helpers'

import { getFrontmatter } from '../helpers/utils'
import type { RuleParams, RuleErrorCallback, Rule } from '@/content-linter/types'

interface Frontmatter {
heroImage?: string
[key: string]: any
}

// Get the list of valid hero images
function getValidHeroImages(): string[] {
const ROOT = process.env.ROOT || '.'
const heroImageDir = path.join(ROOT, 'assets/images/banner-images')

try {
if (!fs.existsSync(heroImageDir)) {
return []
}

const files = fs.readdirSync(heroImageDir)
// Return absolute paths as they would appear in frontmatter
return files.map((file) => `/assets/images/banner-images/${file}`)
} catch {
return []
}
}

export const frontmatterHeroImage: Rule = {
names: ['GHD061', 'frontmatter-hero-image'],
description:
'Hero image paths must be absolute and point to valid images in /assets/images/banner-images/',
tags: ['frontmatter', 'images'],
function: (params: RuleParams, onError: RuleErrorCallback) => {
// Only check index.md files
if (!params.name.endsWith('index.md')) return

const fm = getFrontmatter(params.lines) as Frontmatter | null
if (!fm || !fm.heroImage) return

const heroImage = fm.heroImage

// Check if heroImage is an absolute path
if (!heroImage.startsWith('/')) {
const line = params.lines.find((line: string) => line.trim().startsWith('heroImage:'))
const lineNumber = line ? params.lines.indexOf(line) + 1 : 1
addError(
onError,
lineNumber,
`Hero image path must be absolute (start with /). Found: ${heroImage}`,
line || '',
null, // No fix possible
)
return
}

// Check if heroImage points to banner-images directory
if (!heroImage.startsWith('/assets/images/banner-images/')) {
const line = params.lines.find((line: string) => line.trim().startsWith('heroImage:'))
const lineNumber = line ? params.lines.indexOf(line) + 1 : 1
addError(
onError,
lineNumber,
`Hero image must point to /assets/images/banner-images/. Found: ${heroImage}`,
line || '',
null, // No fix possible
)
return
}

// Check if the file actually exists
const validHeroImages = getValidHeroImages()
if (validHeroImages.length > 0 && !validHeroImages.includes(heroImage)) {
const line = params.lines.find((line: string) => line.trim().startsWith('heroImage:'))
const lineNumber = line ? params.lines.indexOf(line) + 1 : 1
const availableImages = validHeroImages.join(', ')
addError(
onError,
lineNumber,
`Hero image file does not exist: ${heroImage}. Available images: ${availableImages}`,
line || '',
null, // No fix possible
)
}
},
}
2 changes: 2 additions & 0 deletions src/content-linter/lib/linting-rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { ctasSchema } from '@/content-linter/lib/linting-rules/ctas-schema'
import { journeyTracksLiquid } from './journey-tracks-liquid'
import { journeyTracksGuidePathExists } from './journey-tracks-guide-path-exists'
import { journeyTracksUniqueIds } from './journey-tracks-unique-ids'
import { frontmatterHeroImage } from './frontmatter-hero-image'

// Using any type because @github/markdownlint-github doesn't provide TypeScript declarations
// The elements in the array have a 'names' property that contains rule identifiers
Expand Down Expand Up @@ -130,6 +131,7 @@ export const gitHubDocsMarkdownlint = {
journeyTracksLiquid, // GHD058
journeyTracksGuidePathExists, // GHD059
journeyTracksUniqueIds, // GHD060
frontmatterHeroImage, // GHD061

// Search-replace rules
searchReplace, // Open-source plugin
Expand Down
6 changes: 6 additions & 0 deletions src/content-linter/style/github-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ export const githubDocsFrontmatterConfig = {
'partial-markdown-files': false,
'yml-files': false,
},
'frontmatter-hero-image': {
// GHD061
severity: 'error',
'partial-markdown-files': false,
'yml-files': false,
},
}

// Configures rules from the `github/markdownlint-github` repo
Expand Down
Loading
Loading