A toolkit that makes it a breeze to format and lint JavaScript, TypeScript, CSS, and GraphQL files.
Foundry should be installed as a dev-dependency. Run the following command in your terminal:
npm install --save-dev @sumup-oss/foundry
Foundry exposes customizable configurations for the CLI tools it supports. Use the init
command to initialize a configuration file for the tools you would like to use:
npx foundry init
Foundry will launch an interactive prompt to ask you questions about your project, such as whether you are planning to open source it. Once you have answered all questions, Foundry will write the config files (don't worry, it asks before overwriting existing files) and will add scripts to your package.json
file to conveniently run the tools.
Alternatively, you can pass your answers to the init
command directly as flags. This is useful for environments such as CI where interactive prompts cannot be used. Here is an overview of all available options (you can view this help menu by running npx foundry init --help
):
--configDir The directory to write configs to [string] [default: "."]
--overwrite Whether to overwrite existing configs [boolean] [default: false]
--version Show version number [boolean]
--help Show this help menu [boolean]
Foundry adds the following scripts to your package.json
file:
lint
: format JavaScript & TypeScript files and check them for problematic patternslint:fix
: same aslint
, but also try to fix the issueslint:ci
: same aslint
, but optimized for continuous integration workflowslint:css
: check CSS files for problematic patterns
Biome formats your code to look the same after every save and identifies & fixes problematic patterns in your code so you can spot mistakes early. It works on JavaScript, TypeScript, JSON, CSS, and GraphQL files.
Foundry exposes a default config for Biome to extend. Refer to Biome's documentation to learn how to customize the config to your needs.
// biome.jsonc
{
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
"extends": ["@sumup-oss/foundry/biome"]
}
Foundry also generates an .editorconfig
file that is used by Biome, IDEs, and other tools to apply consistent formatting to a variety of supported filetypes.
ESLint identifies and fixes problematic patterns in your code so you can spot mistakes early. It is slower than Biome, but can detect a larger number of issue types and has an established plugin ecosystem. It works on JavaScript and TypeScript files.
Foundry exposes a number ESLint configs to be composed together based on the language, environment, and frameworks used. Refer to ESLint's documentation to familiarize yourself with the configuration format.
// eslint.config.js
import { defineConfig, configs } from '@sumup-oss/foundry/eslint';
export default defineConfig([
configs.ignores,
configs.javascript,
configs.browser,
configs.tests,
]);
Foundry exports the following configuration objects:
- Ignored files:
ignores
- Languages:
javascript
,typescript
- Environments:
browser
,node
- Frameworks:
next
,react
,storybook
,tests
- Open source:
open-source
TypeScript
Note that the typescript
config includes the javascript
config, so it doesn't need to be added separately.
// eslint.config.js
import { defineConfig, configs, files } from '@sumup-oss/foundry/eslint';
export default defineConfig([
configs.ignores,
{
extends: [configs.typescript],
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
// Optionally, disable TypeScript rules in JavaScript files
{
files: files.javascript,
rules: {
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
},
},
]);
Node
// eslint.config.js
import { defineConfig, configs } from '@sumup-oss/foundry/eslint';
export default defineConfig([
configs.ignores,
{
extends: [configs.node],
// Specify which files are executed in Node
files: ['src/app/**/*', 'src/pages/api/**/*', '**/server/**/*'],
// Optionally, customize the lint rules
rules: {
'no-console': 'off',
},
},
]);
Next.js
Note that the next
config includes the react
config, so it doesn't need to be added separately.
// eslint.config.js
import { defineConfig, configs } from '@sumup-oss/foundry/eslint';
import next from '@next/eslint-plugin-next';
export default defineConfig([
configs.ignores,
{
extends: [next.flatConfig.recommended, configs.next],
},
]);
React
// eslint.config.js
import { defineConfig, configs } from '@sumup-oss/foundry/eslint';
import react from 'eslint-plugin-react';
export default defineConfig([
configs.ignores,
configs.browser,
{
extends: [react.configs.flat.recommended, configs.react],
},
]);
Circuit UI
// eslint.config.js
import { defineConfig, configs, files } from '@sumup-oss/foundry/eslint';
import circuitUI from '@sumup-oss/eslint-plugin-circuit-ui';
export default defineConfig([
configs.ignores,
configs.browser,
{
extends: [circuitUI.configs.recommended],
files: [...files.javascript, ...files.typescript],
},
]);
Storybook
Circuit UI
// eslint.config.js
import { defineConfig, configs, files } from '@sumup-oss/foundry/eslint';
import circuitUI from '@sumup-oss/eslint-plugin-circuit-ui';
export default defineConfig([
configs.ignores,
configs.browser,
{
extends: [circuitUI.configs.recommended],
files: [...files.javascript, ...files.typescript],
},
]);
// eslint.config.js
import { defineConfig, configs } from '@sumup-oss/foundry/eslint';
import storybook from 'eslint-plugin-storybook';
export default defineConfig([
configs.ignores,
{
extends: [storybook.configs['flat/recommended'], configs.stories],
},
]);
Jest
// eslint.config.js
import { defineConfig, configs } from '@sumup-oss/foundry/eslint';
import jest from 'eslint-plugin-jest';
export default defineConfig([
configs.ignores,
{
extends: [jest.configs['flat/recommended'], configs.tests],
},
]);
Vitest
// eslint.config.js
import { defineConfig, configs } from '@sumup-oss/foundry/eslint';
import vitest from '@vitest/eslint-plugin';
export default defineConfig([
configs.ignores,
{
extends: [vitest.configs.recommended, configs.tests],
},
]);
Testing Library
// eslint.config.js
import { defineConfig, configs } from '@sumup-oss/foundry/eslint';
import testingLibrary from 'eslint-plugin-testing-library';
export default defineConfig([
configs.ignores,
{
extends: [testingLibrary.configs['flat/react'], configs.tests],
// Optionally, configure a custom test utils file
settings: {
'testing-library/utils-module': 'test-utils',
},
},
]);
Stylelint identifies and fixes problematic patterns in your styles so you can spot mistakes early. It is slower than Biome, but can detect a larger number of issue types. It works on CSS files.
Foundry exposes a default Stylelint config that can be extended and overridden. Refer to Stylelint's documentation to familiarize yourself with the configuration format.
// stylelint.config.js
import { defineConfig } from '@sumup-oss/foundry/stylelint';
export default defineConfig();
CSS Modules
// stylelint.config.js
import { defineConfig } from '@sumup-oss/foundry/stylelint';
export default defineConfig({
extends: ['stylelint-config-css-modules'],
});
lint-staged is a tool for running linters on files staged for your next commit in git
. Together with Husky (see below) it prevents problematic code from being committed.
Foundry exposes a default lint-staged config that can be extended and overridden. Refer to lint-staged's documentation to familiarize yourself with the configuration format.
// lint-staged.config.js
import { defineConfig } from '@sumup-oss/foundry/lint-staged';
export default defineConfig();
Optimize SVGs
import { defineConfig } from '@sumup-oss/foundry/lint-staged';
export default defineConfig({
'*.svg': ['svgo --config svgo.config.js --pretty'],
});
Husky makes setting up git
hooks easy. Whenever someone installs your project, Husky will automatically set up git
hooks as part of its postinstall
script.
Note that Foundry uses Husky v4, the last version to support a JavaScript configuration file.
// husky.config.cjs
const { defineConfig } = require('@sumup-oss/foundry/husky');
module.exports = defineConfig();
Creating and maintaining a JavaScript project can be very tedious. There are tools, configurations, dependency management, and boilerplate. With Foundry, you can fix all of that with a single dependency. It lints, creates files, and keeps the tools up to date. And the best part? You can still get down and dirty with your configurations. But only if you want.
Setting up and maintaining a complex JavaScript project can be very tedious. There are many different dependencies to install (linters, testing frameworks, bundlers) and configurations to set up. Once you have a running project, you end up writing a lot of boilerplate code when creating commonly used files. For example, a React component might come with a spec file (test), a Storybook file (isolated component development), and a service for handling business logic.
It gets much, much worse when you have several (many?) projects. What happens when there is a breaking change in a tooling dependency? What if a team decides you need to add a new linting rule? Nobody wants to go through every project and update those files all the time. And who knows, if they are even the same? Syncing configurations is terrible. Or think about that new engineer you are onboarding. How are they supposed to know how you structure your project, how your components are supposed to look, which files they need to create?
You might think you could solve these issues with a boilerplate repository and some snippets or templates. But you cannot. At least the maintenance problem will not go away.
Toolkits are a way to mitigate these kinds of problems. They encapsulate as much as possible of the toolchain into a single dependency and expose it through a CLI. Doing so gets you the following, probably more!
- You don't need to set up any tooling when creating a new project. Bootstrap it and start coding. ๐
- When you need to update a tooling dependency or change a configuration, do it in the toolkit and update the toolkit dependency in your projects โ preferably in an automated fashion. That's it. โจ
- Make the way you write JavaScript more consistent. All your projects will work exactly the same. ๐
- Easy onboarding. New colleagues will be able to get productive much more quickly. ๐โโ๏ธ
- The number of direct dependencies becomes much smaller and your
package.json
shorter. ๐ธ๏ธ
We were inspired by many toolkit projects, such as create-react-app and kcd-scripts. These projects are opinionated, and so is Foundry. But Foundry is different, in our opinion, because:
- It encapsulates tools and their configuration, but also lets you get down and dirty with the configs in your project.
- It merely proxies the tools you use on a CLI level instead of talking to them through their Node.js APIs. We literally execute the binaries and forward any options you provided.
So please, go ahead and try it.
We want to foster an inclusive and friendly community around our Open Source efforts. Like all SumUp Open Source projects, this project follows the Contributor Covenant Code of Conduct. Please, read it and follow it.
If you feel another member of the community violated our Code of Conduct or you are experiencing problems participating in our community because of another individual's behavior, please get in touch with our maintainers. We will enforce the Code of Conduct.
It is our mission to make easy and fast card payments a reality across the entire world. You can pay with SumUp in more than 30 countries already. Our engineers work in Berlin, Cologne, Sofia, and Sฤo Paulo. They write code in TypeScript, Swift, Ruby, Go, Java, Erlang, Elixir, and more. Want to come work with us? Head to our careers page to find out more.