Skip to content

Commit

Permalink
feat(eslint): add eslint-config-carbon (carbon-design-system#2986)
Browse files Browse the repository at this point in the history
* feat(eslint): add eslint-config-carbon

* feat(eslint): add support for vanilla config

* chore(eslint): hoist eslint deps

* chore(project): fix eslint violations

* chore(project): add lint to ci-check

* chore(eslint): add alias for returns to return

* chore(project): remap return alias to returns

* chore(cli): fix eslint violations

* chore(project): sync yarn.lock

* chore(eslint-config-carbon): sync package.json
  • Loading branch information
joshblack authored Jun 10, 2019
1 parent 30d7f38 commit 6885126
Show file tree
Hide file tree
Showing 126 changed files with 521 additions and 472 deletions.
34 changes: 34 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Build folders
/build
packages/*/build/
packages/*/examples/*/build/
es
lib
dist
umd

node_modules
packages/*/examples/*

# Components
packages/components/demo/*.css
packages/components/demo/*.map
packages/components/demo/*.js
packages/components/demo/js/prism.js
packages/components/demo/hot
!packages/components/demo/index.js
packages/components/dist
packages/components/examples/codesandbox
packages/components/tests/a11y-results
packages/components/tests/coverage
packages/components/es
packages/components/umd
packages/components/scripts
packages/components/css
packages/components/scss
packages/components/html
packages/components/docs/js
packages/components/node_modules

# Sketch
*.sketchplugin
Binary file removed .yarn/offline-mirror/babel-eslint-7.2.3.tgz
Binary file not shown.
Binary file removed .yarn/offline-mirror/eslint-config-carbon-1.0.2.tgz
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/offline-mirror/eslint-plugin-jsdoc-4.8.4.tgz
Binary file not shown.
Binary file not shown.
30 changes: 13 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
"packages": [
"packages/*"
],
"nohoist": [
"**/eslint",
"eslint/**"
]
"nohoist": []
},
"scripts": {
"build": "lerna run build --stream --prefix --npm-client yarn",
Expand All @@ -23,7 +20,7 @@
"doctoc": "doctoc --title '## Table of Contents' docs",
"format": "prettier --write '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd}/**'",
"format:diff": "prettier --list-different '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd,components}/**'",
"format:staged": "prettier --write",
"lint": "eslint packages",
"lint:styles": "stylelint '**/*.{css,scss}' --config ./packages/stylelint-config-elements",
"sync": "carbon-cli sync",
"test": "cross-env BABEL_ENV=test jest",
Expand All @@ -42,6 +39,11 @@
"cross-env": "^5.2.0",
"cross-spawn": "^6.0.5",
"doctoc": "^1.4.0",
"eslint": "^5.16.0",
"eslint-config-carbon": "10.3.0",
"eslint-plugin-jsdoc": "^7.2.3",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.13.0",
"fs-extra": "^7.0.1",
"glob": "^7.1.4",
"husky": "^2.1.0",
Expand Down Expand Up @@ -83,29 +85,23 @@
}
},
"lint-staged": {
"packages/components/**/*.js": [
"yarn format:staged",
"yarn lerna run lint:staged --scope carbon-components",
"**/*.js": [
"prettier --write",
"eslint",
"git add"
],
"packages/components/**/*.scss": [
"yarn format:staged",
"git add"
],
"packages/react/**/*.js": [
"yarn format:staged",
"yarn lerna run lint:staged --scope carbon-components-react",
"git add"
],
"*.js,!packages/components/**/*.js,!packages/react/**/*.js": [
"yarn format:staged",
"git add"
],
"*.md": [
"yarn format:staged",
"git add"
]
},
"eslintConfig": {
"extends": ["eslint-config-carbon"]
},
"prettier": {
"jsxBracketSameLine": true,
"printWidth": 80,
Expand Down
5 changes: 5 additions & 0 deletions packages/bundler/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-console": "OFF"
}
}
3 changes: 0 additions & 3 deletions packages/bundler/src/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

'use strict';

const { reporter } = require('@carbon/cli-reporter');
const program = require('commander');
const path = require('path');
const packageJson = require('../package.json');
const bundlers = require('./bundlers');
const bundle = require('./commands/bundle');
const check = require('./commands/check');
const inline = require('./commands/inline');
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/src/bundlers/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const commonjs = require('rollup-plugin-commonjs');
const nodeResolve = require('rollup-plugin-node-resolve');
const findPackageFolder = require('../tools/findPackageFolder');

async function bundle(entrypoint, options, info) {
async function bundle(entrypoint, options) {
const globals = options.globals ? formatGlobals(options.globals) : {};
const { name } = options;
const packageFolder = await findPackageFolder(entrypoint);
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/src/bundlers/scss.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const autoprefixerOptions = {
browsers: ['last 1 version', 'ie >= 11', 'Firefox ESR'],
};

async function bundle(entrypoint, options, info) {
async function bundle(entrypoint, options) {
reporter.info(`Bundling ${entrypoint}...`);

const basename = options.name || path.basename(entrypoint, '.scss');
Expand Down
3 changes: 0 additions & 3 deletions packages/bundler/src/commands/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ async function check(pattern, { ignore, cwd, list } = {}) {
cwd,
ignore,
});
const defaultOptions = {
includePaths: ['node_modules', '../../node_modules'],
};

reporter.info(`Compiling ${files.length} files...`);

Expand Down
6 changes: 1 addition & 5 deletions packages/bundler/src/commands/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ async function inlineSassDependencies(
];
const inlinedDependencies = (await Promise.all(
allPossibleDependencies.map(async dependency => {
const [
packageFolder,
scssFolder,
localPackageJsonPath,
] = await findSassModule(dependency, cwd);
const [packageFolder, scssFolder] = await findSassModule(dependency, cwd);
if (packageFolder) {
const dependencyOutputFolder = path.join(vendorFolder, dependency);

Expand Down
10 changes: 2 additions & 8 deletions packages/bundler/src/commands/measure.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ const gzipSize = require('gzip-size');
const { reporter } = require('@carbon/cli-reporter');
const compile = require('../tools/compile');

async function measure(
pattern,
{ cwd, entrypoint, monorepo = false, output, ignore = [] }
) {
async function measure(pattern, { cwd, output, ignore = [] }) {
const outputFilename = 'results.json';
const outputFilepath = output
? path.join(output, outputFilename)
Expand All @@ -33,9 +30,6 @@ async function measure(
cwd,
ignore,
});
const defaultOptions = {
includePaths: ['node_modules', '../../node_modules'],
};

const results = await Promise.all(
compile(files.map(file => path.join(cwd, file)))
Expand Down Expand Up @@ -122,7 +116,7 @@ function printResults(prevResults, results) {
head: resultsHeaders.map(label => chalk.gray.yellow(label)),
});

results.forEach((result, index) => {
results.forEach(result => {
const prevResult =
prevResults.find(prevResult => {
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/src/commands/sassdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function sassdoc(pattern, { ignore, cwd, json, output } = {}) {
const jsonFile = await createJson(files);
await fs.ensureDir(DOCS_DIR);
await fs.writeFile(JSON_FILE, JSON.stringify(jsonFile, null, 2));
} catch {
} catch (error) {
reporter.error(`Sassdoc error: ${error}`);
process.exit(1);
}
Expand Down
6 changes: 5 additions & 1 deletion packages/bundler/src/tools/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

'use strict';

const path = require('path');
const sass = require('node-sass');

const defaultOptions = {
Expand All @@ -25,6 +24,11 @@ function compile(filepaths, options) {
...options,
},
(error, result) => {
if (error) {
reject(error);
return;
}

resolve({
result,
filepath,
Expand Down
23 changes: 12 additions & 11 deletions packages/bundler/src/tools/sassdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const slugify = title => {
* Create a JSON file of documented Sass items
* @see {@link http://sassdoc.com/configuration/|Sassdoc configuration}
* @param {string} sourceDir - source directory
* @param {Object} config - configuration object
* @return {Object} json object
* @param {object} config - configuration object
* @returns {object} json object
*/
async function createJson(sourceDir, config) {
config = config || {};
Expand All @@ -56,7 +56,7 @@ async function createJson(sourceDir, config) {
* Remove duplicate objects in `require` and `usedBy` arrays. Array objects have
* `name` and `type` properties, sometimes nested in a `context` object.
* @param {Array} arr - array with potential duplicates
* @return {Array} deduped array
* @returns {Array} deduped array
*/
function dedupeArray(arr) {
return arr.reduce(
Expand All @@ -79,7 +79,7 @@ function dedupeArray(arr) {
* Create a unique Sassdoc item name
* @param {string} name - Sassdoc name
* @param {string} type - Sassdoc type (e.g. `variable`, `mixin`)
* @return {string} unique Sassdoc item name
* @returns {string} unique Sassdoc item name
*/
function createUniqueName(name, type) {
return `${name} [${type}]`;
Expand All @@ -88,7 +88,7 @@ function createUniqueName(name, type) {
/**
* Create a standardized group name
* @param {Array} group - Item's group
* @return {string} group name
* @returns {string} group name
*/
function createGroupName(group) {
return !group || !group[0] || group[0] === 'undefined' ? 'general' : group[0];
Expand All @@ -98,14 +98,15 @@ function createGroupName(group) {
* Create GitHub-flavored markdown anchor link
* @param {string} name - anchor value
* @param {string} heading - anchor link destination
* @return {string} markdown anchor
* @returns {string} markdown anchor
*/
function createAnchorLink(name, heading) {
const anchorLink = heading
.toLowerCase()
.replace(/ /g, '-')
.replace(/[`~!@#$%^&*()+=<>?,./:;"'|{}\[\]\\]/g, '')
.replace(/[`~!@#$%^&*()+=<>?,./:;"'|{}[\]\\]/g, '')
.replace(
// eslint-disable-next-line no-irregular-whitespace
/[ ]/g,
''
);
Expand All @@ -116,7 +117,7 @@ function createAnchorLink(name, heading) {
/**
* Create markdown for Sassdoc item (function, mixin, placeholder, variable)
* @param {string} item - Sassdoc item
* @return {string} item in markdown formatting
* @returns {string} item in markdown formatting
*/
function createMarkdownItem(item) {
let str = '';
Expand Down Expand Up @@ -342,8 +343,8 @@ ${item.example[0].code}
* Create a markdown file of documented Sass items
* @see {@link http://sassdoc.com/configuration/|Sassdoc configuration}
* @param {string} sourceDir - source directory
* @param {Object} config - configuration object
* @return {string} markdown
* @param {object} config - configuration object
* @returns {string} markdown
*/
async function createMarkdown(sourceDir, config) {
config = config || {};
Expand All @@ -353,7 +354,7 @@ async function createMarkdown(sourceDir, config) {
let markdownFile = '';

const documentedItems = data.filter(
(item, index) => item.access === 'public' || item.access === 'private'
item => item.access === 'public' || item.access === 'private'
);

markdownFile += `# Sass API
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/bin/carbon-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* LICENSE file in the root directory of this source tree.
*/

/* eslint-disable no-console */

'use strict';

// Inspired by Create React App
Expand All @@ -20,7 +22,6 @@ process.on('unhandledRejection', error => {
});

var chalk = require('chalk');
var packageJson = require('../package.json');

var currentNodeVersion = process.versions.node;
var semver = currentNodeVersion.split('.');
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const packageJson = require('../package.json');

const commands = [require('./commands/ci-check'), require('./commands/sync')];

async function main({ argv, cwd }) {
async function main({ argv }) {
cli
.scriptName(packageJson.name)
.version(packageJson.version)
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/commands/ci-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

/* eslint-disable no-console */

'use strict';

const { reporter } = require('@carbon/cli-reporter');
Expand All @@ -22,6 +24,7 @@ async function check(args, env) {
};
const tasks = [
'yarn format:diff',
'yarn lint',
`yarn bundler check --ignore '**/@(node_modules|examples|components|react)/**' 'packages/**/*.scss'`,
`cross-env BABEL_ENV=test yarn test --ci --maxWorkers 2 --reporters=default --reporters=jest-junit`,
`cross-env BABEL_ENV=test yarn test:e2e --ci --maxWorkers 2 --reporters=default --reporters=jest-junit`,
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/commands/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const tasks = {

async function sync(args, env) {
const { target } = args;
const { packages, root } = env;
const tasksToRun = target === 'all' ? Object.keys(tasks) : [target];

for (const name of tasksToRun) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/sync/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const defaultIgnorePatterns = [

function run({ packagePaths }) {
return Promise.all(
packagePaths.map(async ({ packageJson, packagePath }) => {
packagePaths.map(async ({ packagePath }) => {
const ignorePath = path.join(packagePath, '.npmignore');
const ignorePatterns = defaultIgnorePatterns.slice();

Expand Down
Loading

0 comments on commit 6885126

Please sign in to comment.