Skip to content
This repository has been archived by the owner on Mar 14, 2022. It is now read-only.

Removes jsHint in favour of ESLint. Adds Babel-Runtime polyfill and t… #293

Merged
merged 36 commits into from
Sep 22, 2015
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a309881
Configures webpack, not working nicely with bower
Apr 1, 2015
8653af1
Removes jsHint in favour of ESLint. Adds Babel-Runtime polyfill and t…
Jul 15, 2015
447eb8b
Passes new eslint rules and removed default rootDirectory path in bab…
Aug 6, 2015
dc51801
Merges master
Aug 6, 2015
08b17d1
Pushes eslint to v1
Aug 6, 2015
f651401
v4.0.0-beta.1
Aug 6, 2015
254d12a
don't allow overwriting of globals [consistent with obt]
matthew-andrews Aug 6, 2015
b0ae681
let npm publish obt with `.eslintrc`
matthew-andrews Aug 6, 2015
dc10ee2
Merge pull request #297 from Financial-Times/no-eslintrc
Aug 6, 2015
f26130e
v4.0.0-beta.2
Aug 6, 2015
31a343c
Merge pull request #295 from Financial-Times/globals
Aug 6, 2015
575972b
Fixes eslint rules and babel path resolver
Aug 10, 2015
5e35a46
Merge branch 'eslint' of https://github.com/Financial-Times/origami-b…
Aug 10, 2015
774a95a
v4.0.0-beta.3
Aug 10, 2015
0bb17d6
Linter now errors with undefined variables being used, like globals
Aug 14, 2015
7408015
v4.0.0-beta.4
Aug 14, 2015
ccef201
Stop linting multiple new lines and adds no-const-assign rule
Aug 17, 2015
d6535b4
v4.0.0-beta.5
Aug 17, 2015
55efaaf
v4.0.0-beta.6
Aug 17, 2015
97f27ff
Fixes merge conflicts
Aug 19, 2015
d4b2932
Removes destFolder test
Aug 19, 2015
542c597
Sets cwd for bower resolver and fixes bug where bower plugin was tryi…
Aug 20, 2015
5ffbf46
Adds custom loaders for babel runtime resolver and textrequirefy. The…
Aug 31, 2015
1411367
Fixes tests and verify
Sep 1, 2015
06edbe7
Adds hacky fix for textrequireify involving forked transform-loader t…
Sep 8, 2015
7fc0257
Removes hack for textrequireify as custom loader now works
Sep 9, 2015
59ebed7
Disables AMD modules, it was breaking the use of ftscroller
Sep 9, 2015
a6c1e0f
Adds proper webpack error logging. Now triggers error on dependency n…
Sep 17, 2015
23bd4fb
Adds a json loader to be able to require json files like in Node and …
Sep 18, 2015
63d9b0c
v4.0.0-beta.7
Sep 18, 2015
016d73e
Removed promise polyfill from tests
Sep 21, 2015
7a6fc6b
Adds tests for requireText, requiring JSONs and syntax and missing de…
Sep 22, 2015
419cc1f
Fix linting errors
Sep 22, 2015
2615f97
Adds comments, updates readme and adds support for having loaders in …
Sep 22, 2015
edeebcd
Merge pull request #302 from Financial-Times/webpack
Sep 22, 2015
fc484af
Fixes merge conflicts from master
Sep 22, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"env": {
"node": true,
"es6": true
},
"ecmaFeatures": {
"modules": false
},
"rules": {
"no-unused-vars": 2,
"no-undef": 2,
"eqeqeq": 2,
"no-underscore-dangle": 0,
"guard-for-in": 2,
"no-extend-native": 2,
"wrap-iife": 2,
"new-cap": 2,
"no-caller": 2,
"strict": [2, "global"],
"quotes": [1, "single"],
"no-loop-func": 2,
"no-irregular-whitespace": 1,
"no-multi-spaces": 2,
"one-var": [2, "never"]
},
"globals": {
"fetch": true
}
}
17 changes: 0 additions & 17 deletions .jshintrc

This file was deleted.

1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.idea/
test/
*.md
.jshintrc
gulpfile.js
.travis.yml
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ All the tasks are built using [gulp](http://gulpjs.com/), and almost all of them
[--buildCss=<file>] Compiled CSS file (default: main.css)
[--buildFolder=<dir>] Compiled assets directory (default: ./build/)
[--scssLintPath=<path>] Custom scss-lint configuration
[--jsHintPath=<path>] Custom JSHint configuration
[--esLintPath=<path>] Custom esLint configuration
[--editorconfigPath=<path>] Custom .editorconfig

### `install`
Expand Down Expand Up @@ -145,8 +145,8 @@ Runs:
* __scssLint(gulp, config)__ Config accepts:
- scssLintPath: `String` Path to your custom 'scss-lint.yml' config file. (Default: 'origami-build-tools/config/scss-lint.yml') _This may be set for product development, but developers of Origami-compliant components are required to accept the default_
- excludeFiles `Array` e.g. `['!**/demo.scss']`
* __jsHint(gulp, config)__ Config accepts:
- jsHintPath: `String` Path to your custom jsHint config file. (Default: 'origami-build-tools/config/jshint.json' _This may be set for product development, but developers of Origami-compliant components are required to accept the default_
* __esLint(gulp, config)__ Config accepts:
- esLintPath: `String` Path to your custom esLint config file. (Default: 'origami-build-tools/config/.eslintrc' _This may be set for product development, but developers of Origami-compliant components are required to accept the default_
- excludeFiles `Array` e.g. `['!**/demo.js']`
* __lintspaces(gulp, config)__ Config accepts:
- editorconfigPath: `String` Path to your '.editorconfig' that lintspaces uses for linting. (Default: 'origami-build-tools/config/.editorconfig') _This may be set for product development, but developers of Origami-compliant components are required to accept the default_
Expand Down
37 changes: 37 additions & 0 deletions config/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"ecmaFeatures": {
"modules": true
},
"env": {
"es6": true,
"browser": true
},
"rules": {
"no-unused-vars": 2,
"no-undef": 2,
"eqeqeq": 2,
"guard-for-in": 2,
"no-extend-native": 2,
"wrap-iife": 2,
"new-cap": 2,
"no-caller": 2,
"no-multi-str": 0,
"dot-notation": 0,
"strict": [2, "global"],
"valid-jsdoc": 1,
"no-irregular-whitespace": 1,
"no-multi-spaces": 2,
"one-var": [2, "never"],
"constructor-super": 2,
"no-this-before-super": 2,
"no-var": 2,
"prefer-const": 1,
"no-const-assign": 2
},
"globals": {
"require": false,
"module": false,
"exports": false,
"requireText": false
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same as config/.eslintrc? If so do we have to duplicate?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it has a difference, that way we can test that it's using the custom config instead of the default one in its corresponding test

26 changes: 0 additions & 26 deletions config/jshint.json

This file was deleted.

2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var obt = require('./lib/origami-build-tools');

gulp.task('verify', function() {
return obt.verify(gulp, {
jsHintPath: '.jshintrc',
esLintPath: '.eslintrc',
editorconfigPath: '.editorconfig'
});
});
Expand Down
10 changes: 5 additions & 5 deletions lib/helpers/command-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
var childProcess = require('child_process');
var which = require('which');
var log = require('./log');
var windows = (process.platform.indexOf("win32") >= 0 || process.platform.indexOf("win64") >= 0);
var windows = (process.platform.indexOf('win32') >= 0 || process.platform.indexOf('win64') >= 0);

function run(command, args, options) {
return new Promise(function(resolve, reject) {
var pro,
stdOut = "",
stdErr = "";
var pro;
var stdOut = '';
var stdErr = '';

if (windows) {
args.unshift('/c', command);
Expand All @@ -31,7 +31,7 @@ function run(command, args, options) {
});

pro.on('close', function(code) {
var output = { "stderr": stdErr, "stdout": stdOut };
var output = { 'stderr': stdErr, 'stdout': stdOut };

if (code !== 0) {
output.err = code;
Expand Down
98 changes: 48 additions & 50 deletions lib/helpers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ function getBuildFolderPath() {
return path.join(process.cwd(), '/build/');
}

function requireIfExists(filePath) {
if (fs.existsSync(filePath)) {
return require(filePath);
} else {
return undefined;
}
}

function getPackageJson() {
return requireIfExists(path.join(process.cwd(), '/package.json'));
}

function packageJsonExists() {
return (typeof getPackageJson() !== 'undefined');
}

function getBowerJson() {
return requireIfExists(path.join(process.cwd(), '/bower.json'));
}

function bowerJsonExists() {
return (typeof getBowerJson() !== 'undefined');
}

function getMainSassPath() {
var sassMainPath = path.join(process.cwd(), '/main.scss');
var bowerJson = getBowerJson();
Expand All @@ -23,9 +47,9 @@ function getMainSassPath() {
}
}
if (isInBowerMain && !fileExists) {
log.primaryError("main.scss is listed in bower.json main, but file doesn't exist.");
log.primaryError('main.scss is listed in bower.json main, but file doesn\'t exist.');
} else if (!isInBowerMain && fileExists) {
log.primaryError("main.scss exists but is not listed in bower.json main.");
log.primaryError('main.scss exists but is not listed in bower.json main.');
}
if (isInBowerMain && fileExists) {
return sassMainPath;
Expand All @@ -35,10 +59,10 @@ function getMainSassPath() {
}

function getMainJsPath() {
var jsMainPath = path.join(process.cwd(), '/main.js'),
bowerJson = getBowerJson(),
fileExists = fs.existsSync(jsMainPath),
isInBowerMain = false;
var jsMainPath = path.join(process.cwd(), '/main.js');
var bowerJson = getBowerJson();
var fileExists = fs.existsSync(jsMainPath);
var isInBowerMain = false;
if (bowerJson) {
if (bowerJson.main instanceof Array && bowerJson.main.indexOf('main.js') > -1) {
isInBowerMain = true;
Expand All @@ -47,9 +71,9 @@ function getMainJsPath() {
}
}
if (isInBowerMain && !fileExists) {
log.primaryError("main.js is listed in bower.json main, but file doesn't exist.");
log.primaryError('main.js is listed in bower.json main, but file doesn\'t exist.');
} else if (!isInBowerMain && fileExists) {
log.primaryError("main.js exists but is not listed in bower.json main.");
log.primaryError('main.js exists but is not listed in bower.json main.');
}
if (isInBowerMain && fileExists) {
return jsMainPath;
Expand All @@ -58,43 +82,19 @@ function getMainJsPath() {
}
}

function requireIfExists(path) {
if (fs.existsSync(path)) {
return require(path);
} else {
return undefined;
}
}

function getPackageJson() {
return requireIfExists(path.join(process.cwd(), '/package.json'));
}

function packageJsonExists() {
return (typeof getPackageJson() !== "undefined");
}

function getBowerJson() {
return requireIfExists(path.join(process.cwd(), '/bower.json'));
}

function bowerJsonExists() {
return (typeof getBowerJson() !== "undefined");
}

function getModuleName() {
var bowerJson = getBowerJson();
if (bowerJson) {
return bowerJson.name;
}
return "";
return '';
}

function recursiveFileSearch(root, ext) {
return new Promise(function(resolve) {
var excluded = ['.git', '.idea', 'bower_components', 'node_modules'],
finder = find(root),
files = [];
var excluded = ['.git', '.idea', 'bower_components', 'node_modules'];
var finder = find(root);
var files = [];
finder.on('directory', function(dir, stat, stop) {
var base = path.basename(dir);
if (excluded.indexOf(base) > -1) {
Expand All @@ -113,17 +113,17 @@ function recursiveFileSearch(root, ext) {
}

function getSassFilesList() {
return recursiveFileSearch(process.cwd(), ".scss");
return recursiveFileSearch(process.cwd(), '.scss');
}

function sassSupportsSilent(files) {
return new Promise(function(resolve, reject) {
var supportsSilent = false,
moduleName = getModuleName();
var supportsSilent = false;
var moduleName = getModuleName();
if (moduleName) {
for (var c = 0; c < files.length; c++) {
var fileContents = fs.readFileSync(files[c], { encoding: "utf-8" });
if (fileContents.indexOf(moduleName + "-is-silent") >= 0) {
var fileContents = fs.readFileSync(files[c], { encoding: 'utf-8' });
if (fileContents.indexOf(moduleName + '-is-silent') >= 0) {
supportsSilent = true;
break;
}
Expand All @@ -135,25 +135,23 @@ function sassSupportsSilent(files) {
});
}

/**
* Get the node_modules directory that will be used when `npm install` is run
* in the current working directory (process.cwd()). This is necessary as npm walks up the
* directory tree until it finds a node_modules directory when npm installing.
*/
// Get the node_modules directory that will be used when `npm install` is run
// in the current working directory (process.cwd()). This is necessary as npm walks up the
// directory tree until it finds a node_modules directory when npm installing.
function getNodeModulesDirectoryInUse() {
return new Promise(function(resolve, reject) {
npmconf.load({}, function(err, conf) {
if (err) {
reject(err);
}
conf.findPrefix(process.cwd(), function(err, pathPrefix) {
if (err) {
reject(err);
conf.findPrefix(process.cwd(), function(e, pathPrefix) {
if (e) {
reject(e);
}
var nodeModulesPath = pathPrefix;

if (pathPrefix) {
nodeModulesPath = path.join(pathPrefix, "node_modules");
nodeModulesPath = path.join(pathPrefix, 'node_modules');
}

resolve(nodeModulesPath);
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require('colors');

var debugLog = function() {};

if (process.env.OBT_DEBUG === "true") {
if (process.env.OBT_DEBUG === 'true') {
debugLog = function(text) {
console.log(String(text).grey);
};
Expand Down
3 changes: 2 additions & 1 deletion lib/helpers/update-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require('colors');

var https = require('https');
var path = require('path');
var Configstore = require('configstore');
var semver = require('semver');
var log = require('./log');
Expand Down Expand Up @@ -39,7 +40,7 @@ function checkVersion() {
}

function getCurrentVersion() {
return require(__dirname + '/../../package.json').version;
return require(path.join(__dirname, '/../../package.json')).version;
}

function updateNotifier() {
Expand Down
Loading