Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

mobify-code-style

mobify192ISC2.8.5

Code style guide and linting tools for Mobify

readme

Mobify Code Style

A repo to document code standards for different languages and provide tools for linting Mobify projects.

NPM version CircleCI

JavaScript (ES5) with Grunt

Typically, we lint our javascript files using Grunt and grunt-eslint. grunt-eslint is a Grunt helper for the ESLint linter.

To add javascript linting to your project:

  1. Install the NPM mobify-code-style and grunt-eslint modules.
  2. Create a Gruntfile if you don't have one already.
  3. Create an .eslintrc.yml file in the root of your project directory
  4. In the initConfig of your gruntfile, add a section for eslint pointing to the correct linting file.

The .eslintrc.yml file should contain, to begin with:

extends:
  - './node_modules/mobify-code-style/es5/mobify-es5.yml'

Sample eslint Grunt config:

eslint:{
    dev: {
        src: ['src/**/*.js'],
        options: {
            // When true, eslint will test _only_ the rules set in the provided
            // configuration file
            reset: false,
            configFile: './.eslintrc.yml'
        }
    }
}

Migrating from ESLint 0.x or 1.x to ESlint 2.x or 3.x

If you upgrade the version of grunt-eslint you use from one that pulls in ESLint 1.x or lower to one that pulls in ESLint 2.x or greater, you must modify the configuration files to include the new style of configuration.

If the Grunt config includes the default config ./node_modules/mobify-code-style/javascript/.eslintrc, replace that with ./.eslintrc.yml, and add an .eslintrc.yml to the project root as described above.

If there are modifications to the lint configuration in the project, please check the migration guides at eslint.org to port the modified lint config to ESLint 3.x.

ES6/JSX

We use ESLint to lint ES6 and React/JSX code. If ESLint is installed in a project, we can use the configuration from this module by creating a file in the project root named .eslintrc.yml. If the project does not use JSX, the file contents should be

extends:
  - './node_modules/mobify-code-style/es6/mobify-es6.yml'

and for a React/JSX project:

extends:
  - './node_modules/mobify-code-style/es6/mobify-es6-react.yml'

If using a custom Webpack configuration, add the lines:

settings:
  import/resolver:
    webpack:
      config: '<path-to-webpack-config>'

to the .eslintrc.yml

Make sure to install the following NPM modules:

  • eslint > 3.0
  • eslint-plugin-import
  • eslint-import-resolver-webpack
  • eslint-plugin-react (for React/JSX linting only)

ESLint and Atom

Find out how to integrate ESLint and Atom Text.

CSS

Our Client Services team's CSS Style Guide. Written with a lot of tender care by @kpeatt and @jeffkamo.

Python

See the python directory of this repo for a standardized pylintrc file and instructions on using pep8, pylint and pyflakes to check Python code.

Documentation

See the docs directory for setup and configuration of Markdown linting.

All Mobify source files should contain copyright headers at the beginning of the file.

See the copyright directory for setup and configuration of the copyright manager tool

changelog

v2.8.5 (May 29, 2019)

  • Remove linebreak-style blocks windows users from linting their code properly #169
  • Add in Responsive Best Practices section, updated references to Adaptive #165

v2.8.4 (October 31, 2017)

  • Add support to copyright tooling for TypeScript files (.ts, .tsx) #164

v2.8.3 (May 31, 2017)

  • Set sass linting rules to un-ignore base styles

v2.8.2 (May 31, 2017)

  • Provided more detailed linting error message in copyright header tool

v2.8.1 (May 8, 2017)

  • Fixes whitespace / newline management in copyright tool
  • Fix to additional space added when --update flag passed into copyright tool

v2.8.0 (May 5, 2017)

  • Adds new copyright-header management tool

v2.7.4 (February 2, 2017)

  • Add new classname prefixes to CSS documentation: pw- and qa-
  • Add links to alternative CSSComb text editor plugins
  • Fix lint-md to work properly on Node.js v6+

v2.7.3

  • Temporarily disable spaced-comment errors, until Astro release builds comply with this rule.

v2.7.2

  • Temporarily downgrade spaced-comment errors to warning level, until Astro release builds comply with this rule.

v2.7.1

  • Re-organized and cleaned up markdown linting files
  • Switched to using no-duplicate-headings-in-section (instead of no-duplicate-headings)
  • Add spaced-comment rule enforcement to ES5 and legacy (ESLint 1.x or lower) linting #132

v2.7.0

  • Remove variable-for-property rule from sass-lint
  • Adds markdown linting via lint-md script
  • Add ESLint and Atom Text integration how-to doc

v2.6.0

  • Remove variable-for-property rule from sass-lint #126
  • Add the eslint jsx-a11y plugin through a new mobify-es6-react-a11y configuration #129

v2.5.3

  • Fix #123 by using react/jsx-wrap-multilines rule
  • Migrate CSSComb documentation from Confluence to code style repo

v2.5.2

  • Fix #43 by updating all underlines in Sass code examples
  • Fix #114 by removing invalid options from CSSComb config file
  • Add a React rule to make sure propTypes are ordered, required ones declared first and callbacks (e.g. onChange) declared last.
  • Update ES6 indent rule on switch statements
  • Add ignore patterns for unused vars/args to the React configuration
  • Ignore non-JS files and node_modules in the ES6 import module
  • Add a new ES5 configuration ported to ESLint 2 and up

v2.5.1

  • Update line length to 200
  • Remove rule for no-unresolved import
  • Remove 'strict' rule for modules

v2.5.0

  • Add an ES6 and JSX standard with lint rules.

v2.4.4

  • Add a template for code-style PRs
  • Go meta! Add some templates of GitHub templates for contributing, issues, and PRs that can be used on other Mobify repos

v2.4.3

  • Add eslint rule + doc entry regarding trailing commas

v2.4.2

  • Add/update documentation for Sass-Lint

v2.4.1

  • Fix some bugs with sass-lint config

v2.4.0

  • Add a sass-lint config file

v2.3.7

  • Add Writing Checklist
  • Fix doc error wrt function expression hoisting
  • Add some more JS code style to the docs

v2.3.6

  • Change CSScomb rule: null leading-zero rule due to CSScomb bug

v2.3.5

  • Add Sass documentation about placeholders and @extends
  • Add CSS documentation on l10n and i18n best practices

v2.3.4

  • Patch CSSComb and scss-lint rules for compatibility
  • LeadingZero aligned to enabled
  • Tweaked property ordering
  • NameFormat to match BEM
  • NestingDepth upped to 4
  • color and background-color properties no longer require explicit Sass variables

v2.3.3

  • Change scss-lint rule: disable the quotes rules
  • Change CSScomb rule: disable the quotes rules

v2.3.2

  • Update documentation: "Tools & Frameworks" section in the CSS introduction

v2.3.1

  • Add an eslint config file for production-ready JS

v2.3.0

  • Add CSSComb
  • Update documentation
  • Update SCSS-lint to 0.42.2

v2.2.4

  • Remove the unnecessary parens rule

v2.2.3

  • Restrict the unnecessary parens rule to functions

v2.2.2

  • Remove enforcement of 'max-statements' and 'max-params' JS rules

v2.2.1

  • Cumulative patch release
  • Update SCSS-lint to 0.40.1

v2.2.0

  • Fixes eslint config to play nicely with Atom's linter-eslint package
  • Adds an eslint config reset file so that our ruleset is an override

v2.1.1

  • Re-publish to work-around NPM issue

v2.1.0

  • Add new rules to .eslintrc to closer match our JS style guidelines.

v2.0.1

  • Adds .eslintrc to allow usage of ESLint
  • Adds Java code style guide
  • Updates to CSS hybrid project conventions