diff --git a/.eslintignore b/.eslintignore index a130f8b70..d32e28f33 100644 --- a/.eslintignore +++ b/.eslintignore @@ -863,6 +863,7 @@ packages/tools/buildServerDocker.js packages/tools/buildServerDocker.test.js packages/tools/bundleDefaultPlugins.js packages/tools/bundleDefaultPlugins.test.js +packages/tools/checkIgnoredFiles.js packages/tools/checkLibPaths.js packages/tools/checkLibPaths.test.js packages/tools/convertThemesToCss.js diff --git a/.github/scripts/run_ci.sh b/.github/scripts/run_ci.sh index 5d218d294..3c42913cb 100755 --- a/.github/scripts/run_ci.sh +++ b/.github/scripts/run_ci.sh @@ -153,6 +153,24 @@ if [ "$IS_PULL_REQUEST" == "1" ] || [ "$IS_DEV_BRANCH" = "1" ]; then fi fi +# ============================================================================= +# Check .gitignore and .eslintignore files - they should be updated when +# new TypeScript files are added by running `yarn run updateIgnored`. +# See coding_style.md +# ============================================================================= + +if [ "$IS_PULL_REQUEST" == "1" ]; then + if [ "$IS_LINUX" == "1" ]; then + echo "Step: Checking for files that should have been ignored..." + + node packages/tools/checkIgnoredFiles.js + testResult=$? + if [ $testResult -ne 0 ]; then + exit $testResult + fi + fi +fi + # ============================================================================= # Find out if we should run the build or not. Electron-builder gets stuck when # building PRs so we disable it in this case. The Linux build should provide diff --git a/.gitignore b/.gitignore index cfeb31adb..4ef50cb79 100644 --- a/.gitignore +++ b/.gitignore @@ -848,6 +848,7 @@ packages/tools/buildServerDocker.js packages/tools/buildServerDocker.test.js packages/tools/bundleDefaultPlugins.js packages/tools/bundleDefaultPlugins.test.js +packages/tools/checkIgnoredFiles.js packages/tools/checkLibPaths.js packages/tools/checkLibPaths.test.js packages/tools/convertThemesToCss.js diff --git a/lint-staged.config.js b/lint-staged.config.js index 477b0b8bf..ffba84cdd 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -13,5 +13,6 @@ module.exports = { '*.{js,jsx,ts,tsx}': [ 'yarn run linter-precommit', 'yarn run checkLibPaths', + 'node packages/tools/checkIgnoredFiles.js', ], }; diff --git a/packages/tools/checkIgnoredFiles.ts b/packages/tools/checkIgnoredFiles.ts new file mode 100644 index 000000000..cda55e8be --- /dev/null +++ b/packages/tools/checkIgnoredFiles.ts @@ -0,0 +1,33 @@ +import { execCommand, getRootDir } from '@joplin/utils'; +import { readFile, writeFile } from 'fs-extra'; +import { chdir } from 'process'; + +const main = async () => { + chdir(await getRootDir()); + + const previousContent = { + '.gitignore': await readFile('.gitignore', 'utf8'), + '.eslintignore': await readFile('.eslintignore', 'utf8'), + }; + + await execCommand('yarn run updateIgnored', { quiet: true }); + + const newContent = { + '.gitignore': await readFile('.gitignore', 'utf8'), + '.eslintignore': await readFile('.eslintignore', 'utf8'), + }; + + if (newContent['.gitignore'] !== previousContent['.gitignore'] || newContent['.eslintignore'] !== previousContent['.eslintignore']) { + await writeFile('.gitignore', previousContent['.gitignore'], 'utf8'); + await writeFile('.eslintignore', previousContent['.eslintignore'], 'utf8'); + throw new Error('.gitignore or .eslintignore would be modified - run `yarn run updateIgnored`'); + } +}; + +if (require.main === module) { +// eslint-disable-next-line promise/prefer-await-to-then -- Old code before rule was applied + main().catch((error) => { + console.error(error); + process.exit(1); + }); +}