Course site

TE 1 - Setting up your Project Repo

On the individual exercises, you had a Github repo and a clone of that repo on your laptop. Because you were the only contributor on the repo, it was less likely for you to have conflicts when pushing/pulling. (If you were writing code on two different computers, you may have experienced some conflicts.)

For you team project, all team members will share a single Github repo. You will see now the power, and challenges, of distributed version control, because you will all be pushing code to the same rep.

One team member will create this repo and then invite the other members to be collaborators.Once the (empty) repo is available on Github, all team members should create their own clone on their own computer.

Then, you will want to set up some directories for your project. I recommend you use a monorepo format, similar to what you had for the individual exercises. In fact, one way to quickly get some structure in place is to copy the code from one team member’s individual exercises.

For this initial setup, you can do the work right in the main branch. It will be helpful if you are all in lab together to do th fbers should pull, and confirm that they see the new files. Take some time together to get used to this rhythm of one person pushing and others pulling.

Adopting Prettier and ESLint

It will also be helpful to get your whole team using the same code styling and linting rules from ther start, so that you don’t waste time with merge conflicts, or arguing about (relatively) trivial issues while collaborating.

One person on the team should install both prettier and eslint using the instructions given here. The team as a whole should agree (come to a consensus) about how to configure each.

Install Prettier

Since you will use prettier throughout your project, you should install it at the root of your repo. It’s only going to be used during development (not run-time), so make sure you use the -D flag.

# in your project repo's root folder
npm install -D prettier

Next, create a .prettierrc file, also in the root. This file does two things:

  1. Allows you to override some of Prettier’s formatting rules, and
  2. Signals to other tools (e,g, your editor) that you are using prettier Inside your prettierrc, you can add the options you wish to set, using YAML. For example, here is my .prettierrc:
{
  "trailingComma": "none",
  "semi": true,
  "singleQuote": false,
  "bracketSameLine": true,
  "htmlWhitespaceSensitivity": "ignore",
  "proseWrap": "always",
  "printWidth": 64
}

Since you will all be using the same configuration, you should come to a consensus within your team of what to set here. The following table will help guide that discussion:

Feature Prettier Option Default Value Your Value?
Indentation Size tabWidth 2
Tabs? (vs Spaces) useTabs FALSE
Semicolons after Statements? semi TRUE
Desired Line Length printWidth 80
Single Quotes? (vs Double) singleQuote FALSE
Trailing Commas trailingComma all
Space inside brackets in object literals bracketSpacing TRUE
Arrow Function Parenthesis arrowParens always

Once you have prettier configured, you can run it on any code that already exists in your repo. You can add this NPM script to your package.json to make this simpler:

"scripts": {
  "format": "prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc",
  ...
}

Now at any time, you just need to say npm run format. Once your team is all using prettier, there should be no need to run this command. In fact, if you run it and it does change the formatting of any files, you may introduce merge conflicts for folks working on branches. That’s why we want to get prettier set up early on, when there is very little code to change.

Install ESLint

While prettier works on a wide range of file types, eslint really only works with Javascript and Typescript. Moreover, because of differences between frontend and backend Javascript, you need to configure it separately for each package.

If you are not using JavaScript or TypeScript for your backend, you only need to install eslint in your frontend package.

First, let’s install eslint in your frontend package. Change directories to there, and then type:

# in your frontend package (e.g., packages/react-frontend)
npm install -D eslint @eslint/compat @eslint/eslintrc @eslint/js globals

If you are using React, you should also install the following:

npm install -D eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-refresh

Other frontend frameworks may offer their own eslint plugins. Check the docs for your framework of choice.

ESLint has many more configuration options than prettier. You can start off with a basic set and then within your team decide what you like. It’s easy to turn on/off rules later, because ESLint (unlike prettier) does not modify your code.

To configure ESLint, you will create a file called eslint.config.js in your package. If you used npm create vite to start your frontend package (like we did in IE1), you may already have one there.

If not, here is a sample one for a typical React frontend:

// packages/react-frontend/eslint.config.js
import js from "@eslint/js";
import globals from "globals";
import react from "eslint-plugin-react";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";

export default [
  { ignores: ["dist"] },
  {
    files: ["**/*.{js,jsx}"],
    languageOptions: {
      ecmaVersion: 2020,
      globals: globals.browser,
      parserOptions: {
        ecmaVersion: "latest",
        ecmaFeatures: { jsx: true },
        sourceType: "module",
      },
    },
    settings: { react: { version: "18.3" } },
    plugins: {
      react,
      "react-hooks": reactHooks,
      "react-refresh": reactRefresh,
    },
    rules: {
      ...js.configs.recommended.rules,
      ...react.configs.recommended.rules,
      ...react.configs["jsx-runtime"].rules,
      ...reactHooks.configs.recommended.rules,
      "react/jsx-no-target-blank": "off",
      "react-refresh/only-export-components": [
        "warn",
        { allowConstantExport: true },
      ],
      "react/prop-types": "off",
    },
  },
];

In your backend, ESLint installation and configuration is much simpler. Start by installing ESLint itself:

# in your backend package (e.g., packages/express-backend)
npm install -D eslint @eslint/compat @eslint/eslintrc @eslint/js

There are no plugins required for a typical NodeJS backend. You can proceed to creating the eslint.config.js file in the backend package. Here is a basic one:

// packages/express-backend/eslint.config.js
import js from "@eslint/js";

export default [
  { ignores: ["dist"] },
  {
    files: ["**/*.{js}"],
    languageOptions: {
      ecmaVersion: 2020,
      parserOptions: {
        ecmaVersion: "latest",
        sourceType: "module",
      },
    },
    rules: {
      ...js.configs.recommended.rules,
    },
  },
];

Add a CONTRIBUTING.md file

Create this file in the root of your repo. Here is where you explain to your teammates how to follow the style that you’ve decided on. (Imagine there will be more developers who want to join your team in the future, and you need to explain the tools you’ve set up.)

Editor Integration

Each developer on your team will need to set up their own editor integration.

Depending on the IDE(s) you’re using, these tools be pluggable into your IDE. Otherwise, you can run them from the command line as well. Each team member should figure out how they are going to integrate the tools into their own workflow.

Prettier has a page listing known editor integrations(https://prettier.io/docs/en/editors). So does ESLint(https://eslint.org/docs/latest/use/integrations). If you don’t see your editor listed here, look in the documentation for the editor itself.

Turning it in.

When you are finished with this exercise, turn it in by submitting a link to your Github repo below. Everything described here should be merged into the main branch.

Only one member of each team needs to submit this exercise.