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

Linting fix #299

Merged
merged 21 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5035c51
Fix lint command not exiting on fatalErrors and add tests
leeyi45 Mar 26, 2024
a1dc889
Add plugin to check js-slang imports to make sure they're supported
leeyi45 Mar 26, 2024
acb1c90
Add gl resolution
leeyi45 Mar 26, 2024
e129633
Fix broken lint command again :(
leeyi45 Mar 26, 2024
c425636
Run with updated linting configuration
leeyi45 Mar 26, 2024
4b557bd
Merge commit 'f79ed87f3ae0fe386aae695d037ee7ef40334e0b' into linting-fix
leeyi45 Mar 26, 2024
96ea770
Add missing exports to exports filter
leeyi45 Mar 26, 2024
dc8680f
Fix broken linting again :(
leeyi45 Mar 26, 2024
8034728
Fix json command test not working
leeyi45 Mar 27, 2024
bf66f6a
Fix certain commands running on tabs when they aren't supposed to
leeyi45 Mar 27, 2024
ce0a629
Use different manifest readers to properly avoid loading unnecessary …
leeyi45 Mar 27, 2024
7e9a0fe
Fix broken tests and imports
leeyi45 Mar 27, 2024
a9360a1
Allow linting for certain js files
leeyi45 Apr 1, 2024
b84389e
Simplify tsconfig structure
leeyi45 Apr 1, 2024
ef2361a
Rename create command to template to avoid conflicting with native Ya…
leeyi45 Apr 1, 2024
c895492
Merge branch 'master' into linting-fix
RichDom2185 Apr 1, 2024
3c3360d
Put the watch function back
leeyi45 Apr 1, 2024
b13bc79
Further linting changes
leeyi45 Apr 1, 2024
fc223b7
Put tsconfig option in watch command
leeyi45 Apr 1, 2024
3ccb1b3
Merge branch 'master' into linting-fix
leeyi45 Apr 2, 2024
2ab3b36
Merge branch 'master' into linting-fix
RichDom2185 Apr 5, 2024
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
113 changes: 46 additions & 67 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,18 @@ import tseslint from 'typescript-eslint';
const todoTreeKeywordsWarning = ['TODO', 'TODOS', 'TODO WIP', 'FIXME', 'WIP'];
const todoTreeKeywordsAll = [...todoTreeKeywordsWarning, 'NOTE', 'NOTES', 'LIST'];

const OFF = 0;
martin-henz marked this conversation as resolved.
Show resolved Hide resolved
const WARN = 1;
const ERROR = 2;

/**
* @type {import('eslint').Linter.FlatConfig[]}
*/
export default [
{
// global ignores
ignores: [
'src/**/samples/**',
'**/*.snap',
'build/**',
'scripts/**/templates/templates/**',
'scripts/bin.js',
'build/**',

// TODO: Remove these when eslint supports import assertions
// or if we decide to use the babel parser that's fine too
'scripts/scripts_manager.js',
'scripts/jest.config.js'
'src/**/samples/**'
]
},
js.configs.recommended,
Expand All @@ -45,9 +37,9 @@ export default [
'@stylistic': stylePlugin,
},
rules: {
'import/no-duplicates': [WARN, { 'prefer-inline': false }],
'import/no-duplicates': ['warn', { 'prefer-inline': false }],
'import/order': [
WARN,
'warn',
{
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
alphabetize: {
Expand All @@ -57,17 +49,17 @@ export default [
}
],

'@stylistic/brace-style': [WARN, '1tbs', { allowSingleLine: true }],
'@stylistic/eol-last': WARN,
'@stylistic/indent': [WARN, 2, { SwitchCase: 1 }],
'@stylistic/no-mixed-spaces-and-tabs': WARN,
'@stylistic/no-multi-spaces': WARN,
'@stylistic/no-multiple-empty-lines': [WARN, { max: 1, maxEOF: 0 }],
'@stylistic/no-trailing-spaces': WARN,
'@stylistic/quotes': [WARN, 'single', { avoidEscape: true }],
'@stylistic/semi': [WARN, 'always'],
'@stylistic/brace-style': ['warn', '1tbs', { allowSingleLine: true }],
'@stylistic/eol-last': 'warn',
'@stylistic/indent': ['warn', 2, { SwitchCase: 1 }],
'@stylistic/no-mixed-spaces-and-tabs': 'warn',
'@stylistic/no-multi-spaces': 'warn',
'@stylistic/no-multiple-empty-lines': ['warn', { max: 1, maxEOF: 0 }],
'@stylistic/no-trailing-spaces': 'warn',
'@stylistic/quotes': ['warn', 'single', { avoidEscape: true }],
'@stylistic/semi': ['warn', 'always'],
'@stylistic/spaced-comment': [
WARN,
'warn',
'always',
{ markers: todoTreeKeywordsAll }
],
Expand All @@ -84,15 +76,15 @@ export default [
'@typescript-eslint': tseslint.plugin,
},
rules: {
'no-unused-vars': OFF, // Use the typescript eslint rule instead
'no-unused-vars': 'off', // Use the typescript eslint rule instead

'@typescript-eslint/ban-types': OFF, // Was ERROR
'@typescript-eslint/no-duplicate-type-constituents': OFF, // Was ERROR
'@typescript-eslint/no-explicit-any': OFF, // Was ERROR
'@typescript-eslint/no-redundant-type-constituents': OFF, // Was ERROR
'@typescript-eslint/no-unused-vars': [WARN, { argsIgnorePattern: '^_' }], // Was ERROR
'@typescript-eslint/prefer-ts-expect-error': WARN,
'@typescript-eslint/sort-type-constituents': WARN,
'@typescript-eslint/ban-types': 'off', // Was 'error'
'@typescript-eslint/no-duplicate-type-constituents': 'off', // Was 'error'
'@typescript-eslint/no-explicit-any': 'off', // Was 'error'
'@typescript-eslint/no-redundant-type-constituents': 'off', // Was 'error'
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], // Was 'error'
'@typescript-eslint/prefer-ts-expect-error': 'warn',
'@typescript-eslint/sort-type-constituents': 'warn',
}
},
{
Expand All @@ -102,57 +94,50 @@ export default [
'react-hooks': reactHooksPlugin
},
rules: {
'react-hooks/rules-of-hooks': ERROR,
'react-hooks/rules-of-hooks': 'error',

'@stylistic/jsx-equals-spacing': [WARN, 'never'],
'@stylistic/jsx-indent': [WARN, 2],
'@stylistic/jsx-indent-props': [WARN, 2],
'@stylistic/jsx-props-no-multi-spaces': WARN,
'@stylistic/jsx-equals-spacing': ['warn', 'never'],
'@stylistic/jsx-indent': ['warn', 2],
'@stylistic/jsx-indent-props': ['warn', 2],
'@stylistic/jsx-props-no-multi-spaces': 'warn',
}
},
{
// Rules for bundles and tabs
files: ['src/**/*.ts*'],
ignores: [
'**/__tests__/**/*.ts*',
'**/__mocks__/**/*.ts',
],
languageOptions: {
globals: globals.browser,
parserOptions: {
project: './src/tsconfig.json'
}
},
rules: {
'prefer-const': WARN, // Was ERROR
'prefer-const': 'warn', // Was 'error'

'@typescript-eslint/no-namespace': OFF, // Was ERROR
'@typescript-eslint/no-var-requires': WARN, // Was ERROR
'@typescript-eslint/switch-exhaustiveness-check': ERROR,
'@typescript-eslint/no-namespace': 'off', // Was 'error'
'@typescript-eslint/no-var-requires': 'warn', // Was 'error'
'@typescript-eslint/switch-exhaustiveness-check': 'error',
},
},
{
// Rules for scripts
files: ['scripts/**/*.ts'],
ignores: [
'**/__tests__/**/*.ts',
'**/__mocks__/**/*.ts',
'scripts/src/templates/templates/**/*.ts*'
],
ignores: ['scripts/src/templates/templates/**/*.ts*'],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
project: './scripts/tsconfig.json'
}
},
rules: {
'import/extensions': [ERROR, 'never', { json: 'always' }],
'no-constant-condition': OFF, // Was ERROR,
'@stylistic/arrow-parens': [WARN, 'as-needed'],
'import/extensions': ['error', 'never', { json: 'always' }],
'no-constant-condition': 'off', // Was 'error',

'@typescript-eslint/prefer-readonly': WARN,
'@typescript-eslint/require-await': ERROR,
'@typescript-eslint/return-await': [ERROR, 'in-try-catch']
'@stylistic/arrow-parens': ['warn', 'as-needed'],

'@typescript-eslint/prefer-readonly': 'warn',
'@typescript-eslint/require-await': 'error',
'@typescript-eslint/return-await': ['error', 'in-try-catch']
},
settings: {
'import/internal-regex': '^@src/',
Expand Down Expand Up @@ -180,20 +165,14 @@ export default [
'**/__mocks__/**/*.ts*',
'**/jest.setup.ts'
],
ignores: ['**/*.snap'],
languageOptions: {
parserOptions: {
project: './tsconfig.test.json'
}
},
rules: {
...jestPlugin.configs['flat/recommended'].rules,
'jest/expect-expect': [ERROR, { assertFunctionNames: ['expect*'] }],
'jest/no-alias-methods': OFF,
'jest/no-conditional-expect': OFF,
'jest/no-export': OFF,
'jest/require-top-level-describe': OFF,
'jest/valid-describe-callback': OFF
'jest/expect-expect': ['error', { assertFunctionNames: ['expect*'] }],
'jest/no-alias-methods': 'off',
'jest/no-conditional-expect': 'off',
'jest/no-export': 'off',
'jest/require-top-level-describe': 'off',
'jest/valid-describe-callback': 'off'
}
}
];
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "Apache-2.0",
"scripts-info": {
"//NOTE": "Run `npm i npm-scripts-info -g` to install once globally, then run `npm-scripts-info` as needed to list these descriptions",
"create": "Interactively initialise a new bundle or tab from their templates",
"template": "Interactively initialise a new bundle or tab from their templates",
"devserver": "Start the tab development server",
"devserver:lint": "Lint code related to the dev server",
"devserver:tsc": "Run tsc over dev server code",
Expand All @@ -29,18 +29,18 @@
"scripts": {
"build": "yarn scripts build",
"build:help": "yarn scripts build --help",
"create": "yarn scripts create",
"dev": "yarn scripts build modules && yarn serve",
"docs": "yarn scripts build docs",
"lint": "yarn scripts lint",
"prepare": "husky install",
"postinstall": "patch-package && yarn scripts:build",
"scripts": "node --max-old-space-size=4096 scripts/bin.js",
"serve": "http-server --cors=* -c-1 -p 8022 ./build",
"template": "yarn scripts template",
"test": "yarn scripts test",
"test:all": "yarn test && yarn scripts:test",
"test:watch": "yarn scripts test --watch",
"watch": "yarn scripts watch",
"watch": "yarn scripts build watch",
"devserver": "vite",
"devserver:lint": "eslint devserver",
"devserver:tsc": "tsc --project devserver/tsconfig.json",
Expand Down
12 changes: 6 additions & 6 deletions scripts/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pathsToModuleNameMapper } from 'ts-jest'
import tsconfig from './tsconfig.json' with { type: 'json' }
import { pathsToModuleNameMapper } from 'ts-jest';
import tsconfig from './tsconfig.json' with { type: 'json' };

/**
* @type {import('jest').Config}
Expand All @@ -9,12 +9,12 @@ const jestConfig = {
displayName: 'Scripts',
extensionsToTreatAsEsm: ['.ts'],
testEnvironment: 'node',
moduleNameMapper: pathsToModuleNameMapper(tsconfig.compilerOptions.paths, { prefix: "<rootDir>/" }),
moduleNameMapper: pathsToModuleNameMapper(tsconfig.compilerOptions.paths, { prefix: '<rootDir>/' }),
preset: 'ts-jest/presets/default-esm',
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
testMatch: [
'<rootDir>/src/**/__tests__/**/*.test.ts',
],
}
};

export default jestConfig
export default jestConfig;
46 changes: 23 additions & 23 deletions scripts/scripts_manager.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Command } from '@commander-js/extra-typings'
import { build as esbuild } from 'esbuild'
import jest from 'jest'
import _ from 'lodash'
import pathlib from 'path'
import { fileURLToPath } from 'url'
import tsconfig from './tsconfig.json' with { type: 'json' }
import { pathsToModuleNameMapper } from 'ts-jest'
import pathlib from 'path';
import { fileURLToPath } from 'url';
import { Command } from '@commander-js/extra-typings';
import { build as esbuild } from 'esbuild';
import jest from 'jest';
import _ from 'lodash';
import { pathsToModuleNameMapper } from 'ts-jest';
import tsconfig from './tsconfig.json' with { type: 'json' };

function cjsDirname(url) {
return pathlib.join(pathlib.dirname(fileURLToPath(url)))
return pathlib.join(pathlib.dirname(fileURLToPath(url)));
}

async function buildScripts({ dev }) {
const dirname = cjsDirname(import.meta.url)
const dirname = cjsDirname(import.meta.url);

await esbuild({
bundle: true,
Expand All @@ -28,34 +28,34 @@ async function buildScripts({ dev }) {
plugins: [{
name: 'Paths to module name translator',
setup(pluginBuild) {
const replacements = pathsToModuleNameMapper(tsconfig.compilerOptions.paths)
const replacements = pathsToModuleNameMapper(tsconfig.compilerOptions.paths);
Object.entries(replacements).forEach(([key, value]) => {
const filter = new RegExp(key, 'gm')
const filter = new RegExp(key, 'gm');

pluginBuild.onResolve({ filter }, args => {
const newPath = args.path.replace(filter, value)
const newPath = args.path.replace(filter, value);
return pluginBuild.resolve(
newPath,
{
kind: args.kind,
resolveDir: dirname,
},
)
})
})
);
});
});
}
}]
})
});
}

const buildCommand = new Command('build')
.description('Build scripts')
.option('--dev', 'Use for script development builds')
.action(buildScripts)
.action(buildScripts);

/**
* Run Jest programmatically
* @param {string[]} patterns
* @param {string[]} patterns
* @returns {Promise<void>}
*/
function runJest(patterns) {
Expand All @@ -71,15 +71,15 @@ function runJest(patterns) {
const jestArgs = args.concat(filePatterns.map((pattern) => pattern.split(pathlib.win32.sep)
.join(pathlib.posix.sep)));

return jest.run(jestArgs, './scripts/jest.config.js')
return jest.run(jestArgs, './scripts/jest.config.js');
}

const testCommand = new Command('test')
.description('Run tests for script files')
.allowUnknownOption()
.action((_, command) => runJest(command.args))
.action((_, command) => runJest(command.args));

await new Command()
.addCommand(buildCommand)
.addCommand(testCommand)
.parseAsync()
.parseAsync();
Loading
Loading