Skip to content
This repository has been archived by the owner on Aug 1, 2021. It is now read-only.

Commit

Permalink
#37 move eslint into src
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonLi8 committed Jan 23, 2020
1 parent b42432a commit a4c09bf
Show file tree
Hide file tree
Showing 23 changed files with 26 additions and 31 deletions.
1 change: 0 additions & 1 deletion eslint/config/amd-rules.js

This file was deleted.

1 change: 0 additions & 1 deletion eslint/config/best-practices-rules.js

This file was deleted.

1 change: 0 additions & 1 deletion eslint/config/es6-rules.js

This file was deleted.

1 change: 0 additions & 1 deletion eslint/config/import-rules.js

This file was deleted.

1 change: 0 additions & 1 deletion eslint/config/node-rules.js

This file was deleted.

1 change: 0 additions & 1 deletion eslint/config/strict-rules.js

This file was deleted.

1 change: 0 additions & 1 deletion eslint/config/style-rules.js

This file was deleted.

1 change: 0 additions & 1 deletion eslint/config/variable-rules.js

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"github-label-sync": "^1.4.2",
"grunt": "~1.0.4",
"ignore": "^5.1.4",
"md5": "^2.2.1",
"requirejs": "^2.3.6",
"shelljs": "^0.8.3",
"terser": "^4.6.3",
Expand Down
28 changes: 12 additions & 16 deletions src/Linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* Currently only lints javascript files using ESlint (see https://eslint.org/). However, there are plans to
* support different file types in the future.
*
* The configuration for ESlint can be found ../eslint/.eslintrc.js (relative to this file). It uses some default rules
* (see documentation: https://eslint.org/docs/rules/) but also implements custom rules (see ../eslint/rules).
* The configuration for ESlint can be found in ./eslint/.eslintrc.js (relative to this file). It uses some default
* rules (see documentation: https://eslint.org/docs/rules/) but also implements custom rules (see ./eslint/rules).
*
* @author Brandon Li <[email protected]>
*/
Expand All @@ -23,48 +23,44 @@ module.exports = ( () => {
// modules
const eslint = require( 'eslint' );
const grunt = require( 'grunt' );
const md5 = require( 'md5' );
const path = require( 'path' );
const Util = require( './Util' );

class Linter {

/**
* Lints the entire root directory that invoked the command, using the ESlint configuration defined in
* ../eslint/.eslintrc.js (relative to this file). Uses some custom rules (see ../eslint/rules).
* ./eslint/.eslintrc.js (relative to this file). Uses some custom rules (see ./eslint/rules).
* @public
*
* @param {boolean} useCache - indicates if the ESlint cache should be used. Caching doesn't re-lint files that
* haven't changed.
* @returns {Object} - ESlint report object
*/
static eslint( useCache ) {
Util.assert( typeof useCache === 'boolean', `invalid useCache: ${ useCache }` );

// Use the Node.js ESLint API. See https://eslint.org/docs/developer-guide/nodejs-api.
const linter = new eslint.CLIEngine( {

// Use the ESlint configuration defined in ../eslint/.eslintrc.js
// Use the ESlint configuration defined in ./eslint/.eslintrc.js
baseConfig: {
extends: [ `${ Util.GRUNT_CONFIG_PATH }/eslint/.eslintrc.js` ]
extends: [ `${ Util.GRUNT_CONFIG_PATH }/src/eslint/.eslintrc.js` ]
},

// Current working directory - Lints the entire root directory that invoked the command
cwd: Util.REPO_PATH,

// Caching checks changed files or when the list of rules is changed. Changing the implementation of
// a custom rule does not invalidate the cache. Caches are formated in .eslintcache files inside of
// ../eslint/cache/**.eslintcache (relative to this file).
// a custom rule does not invalidate the cache.
cache: useCache,

// Indicates where to store the target-specific cache file. Use md5 to hash the file name. This path is relative
// to the root directory of which the command was invoked, so we use the Util.GRUNT_CONFIG_PATH to find the
// correct path inside of grunt-config.
cacheFile: `${ Util.GRUNT_CONFIG_PATH }/eslint/cache/${ md5( path.basename( Util.REPO_PATH ) ) }.eslintcache`,
// Indicates where to store the target-specific cache file. This path is relative to the root directory of which
// the command was invoked, so we use the Util.REPO_PATH to find the correct path inside of the repo.
cacheFile: `${ Util.REPO_PATH }/.eslintcache`,

// Indicates where the custom rules are. This path is relative to the root directory of which the command was
// invoked, so we use the Util.GRUNT_CONFIG_PATH to find the correct rules path located inside of grunt-config
rulePaths: [ `${ Util.GRUNT_CONFIG_PATH }/eslint/rules` ],
// Indicates where the custom rules are. This path is relative to grunt-config, so we use
// Util.GRUNT_CONFIG_PATH to find the correct rules path located inside of grunt-config
rulePaths: [ `${ Util.GRUNT_CONFIG_PATH }/src/eslint/rules` ],

// Files and directories to skip when linting.
ignorePattern: Util.IGNORE_PATTERN
Expand Down
2 changes: 1 addition & 1 deletion eslint/.eslintrc.js → src/eslint/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2019-2020 Brandon Li. All rights reserved.
// Copyright © 2020 Brandon Li. All rights reserved.

/**
* ESlint configuration file. See https://eslint.org/docs/user-guide/configuring for documentation of implementing
Expand Down
1 change: 1 addition & 0 deletions src/eslint/config/amd-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Copyright © 2020 Brandon Li. All rights reserved.
1 change: 1 addition & 0 deletions src/eslint/config/best-practices-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Copyright © 2020 Brandon Li. All rights reserved.
1 change: 1 addition & 0 deletions src/eslint/config/es6-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Copyright © 2020 Brandon Li. All rights reserved.
1 change: 1 addition & 0 deletions src/eslint/config/import-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Copyright © 2020 Brandon Li. All rights reserved.
1 change: 1 addition & 0 deletions src/eslint/config/node-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Copyright © 2020 Brandon Li. All rights reserved.
1 change: 1 addition & 0 deletions src/eslint/config/strict-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Copyright © 2020 Brandon Li. All rights reserved.
1 change: 1 addition & 0 deletions src/eslint/config/style-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Copyright © 2020 Brandon Li. All rights reserved.
1 change: 1 addition & 0 deletions src/eslint/config/variable-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Copyright © 2020 Brandon Li. All rights reserved.
2 changes: 1 addition & 1 deletion eslint/rules/bad-text.js → src/eslint/rules/bad-text.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2019-2020 Brandon Li. All rights reserved.
// Copyright © 2020 Brandon Li. All rights reserved.
/* eslint bad-text: 0 */

/**
Expand Down
4 changes: 2 additions & 2 deletions eslint/rules/copyright.js → src/eslint/rules/copyright.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2019-2020 Brandon Li. All rights reserved.
// Copyright © 2020 Brandon Li. All rights reserved.

/**
* Custom ESlint rule that enforces the first line of each file to be a correctly implemented copyright statement,
Expand All @@ -16,7 +16,7 @@ module.exports = ( () => {
'use strict';

// modules
const Copyright = require( '../../src/Copyright' );
const Copyright = require( '../../Copyright' );

return {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2019-2020 Brandon Li. All rights reserved.
// Copyright © 2020 Brandon Li. All rights reserved.

/**
* Custom ESlint rule that checks that the module name (case sensitive) of a RequireJS statement matches the variable.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2019-2020 Brandon Li. All rights reserved.
// Copyright © 2020 Brandon Li. All rights reserved.

/**
* Custom ESlint rule that checks that the RequireJS statements of groups are alphabetically sorted (case-insensitive).
Expand Down

0 comments on commit a4c09bf

Please sign in to comment.