Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
chore: code style change, lint using modified eslint-config-airbnb
Browse files Browse the repository at this point in the history
Following #128 and various discussions we already had on code style, I
configured our lint on airbnb/javascript style guide using eslint.

I chose to stay with ESLint because:
- it's becoming a good linting standard and has the best support for
both ES6,
jsx, react..
- already what we know, do not have to change again
- other alternatives were not as good as what we wanted

Not a single linter has a "Automatically reformat this whole code
option, do it well". ESLint has some wishes for ESLint 2.0 but may be
later.

In the end we will struggle a little bit on following our own Algolia
style at the begining but it will be worth it soon as we will be more
and more JavaScript`er. I recall @bobylito wanting to do so early on
when we both joined. Well, now it's time!

The goal of this PR is to provide a solid ground for our linting rules
amongst all our JS projects.

The currently picked coding style is the one from Airbnb, with
modifications.

You can find the modified rules here: https://github.com/algolia
/eslint-config-algolia#rules

I assume there are some rules like spacing aroud parentheses and
brackets that will be a big change for you @bobylito (and it's your
project so I am dropping your name here!)

But we need to try to find a style that is both OUR style and also
will
not give our future open source contributors too much WTF moments when
encountering our style.

On this subject, http://sideeffect.kr/popularconvention/#javascript is
a
good data based source.

We can discuss, add, remove, edit the rules as long as we do not
discuss them
every week!

Other projects:

- Original feross/standard:
After trying it I discovered some rules were not strict enough and
would lead to again style discussions. Has some sort of formatter but
not very good. Based on eslint.

Ref:
- standard/standard#180

- JSCS:
I tried JSCS: good but only oriented on style, no rules on unused
variables or ways to prevent bugs like eslint does. Has some sort of
formatter, but not very good.

Ultimately eslint will have a good formatter, in the meantime we will
all switch to some new coding style, for good :-)?

fixes #128
  • Loading branch information
vvo committed Jul 6, 2015
1 parent c57c97e commit 6aefd52
Show file tree
Hide file tree
Showing 46 changed files with 2,373 additions and 2,431 deletions.
41 changes: 4 additions & 37 deletions .eslintrc
@@ -1,39 +1,6 @@
{
"env" : {
"node": true,
"browser": true
},
"rules" : {
"brace-style": [2, "stroustrup", { "allowSingleLine": true }],
"camelcase" : 1,
"comma-spacing": [2, {"before": false, "after": true}],
"comma-style": [2, "last"],
"consistent-return" : 2,
"consistent-this": [1, "self"],
"curly" : [2,"multi-line"],
"default-case": 1,
"eqeqeq": [2, "smart"],
"global-strict" : 0,
"indent": [2, 2],
"key-spacing" : [1, { "beforeColon" : true, "afterColon" : true }],
"new-cap" : 2,
"no-extra-bind" : 1,
"no-multiple-empty-lines" : 1,
"no-multi-spaces": 1,
"no-spaced-func": 1,
"no-trailing-spaces" : 2,
"no-underscore-dangle": 0,
"quotes" : [1, "double"],
"semi": 2,
"space-before-blocks": 1,
"space-before-function-parentheses": [1, "never"],
"space-infix-ops": 1,
"space-in-parens": [1, "always"],
"strict" : [2, "global"],
"valid-jsdoc": [2, { "requireReturnDescription": false }]
},
"globals" : {
"module" : true,
"require" : true
}
"extends": [
"eslint-config-airbnb",
"eslint-config-algolia"
]
}
8 changes: 4 additions & 4 deletions .jsdoc
@@ -1,9 +1,9 @@
{
"plugins": ["plugins/markdown"],
"opts" : {
"template" : "node_modules/minami"
"opts": {
"template": "node_modules/minami"
},
"markdown" : {
"anchorInHeadings" : true
"markdown": {
"anchorInHeadings": true
}
}
100 changes: 50 additions & 50 deletions CHANGELOG
Expand Up @@ -4,85 +4,85 @@ UNRELEASED
* test: add CI testing (browsers, phantom, node, io)

2.1.2 - 2015-06-26
* FIX : #113 support for attributes hightlightPreTag and hightlighPostTag
* FIX : #112 distinct = undefined sent to the server
* FIX : #110 helper.hasRefinements() now checks for numerics
* FIX : #106 convert refinements to string
* DOC : Update theme + fix (github.com/algolia/minami)
* DOC : Fix misc links and descrition and added samples of objects
* DOC : Added a cheat sheet in the generated documentation
* FIX: #113 support for attributes hightlightPreTag and hightlighPostTag
* FIX: #112 distinct = undefined sent to the server
* FIX: #110 helper.hasRefinements() now checks for numerics
* FIX: #106 convert refinements to string
* DOC: Update theme + fix (github.com/algolia/minami)
* DOC: Fix misc links and descrition and added samples of objects
* DOC: Added a cheat sheet in the generated documentation

2.1.1 - 2015-06-19
* FIX : #107 Apply rules to distinct to prevent the API to return an error
* FIX : make algoliasearch-helper requireable + browserifyable by removing the global envify transform
* FIX: #107 Apply rules to distinct to prevent the API to return an error
* FIX: make algoliasearch-helper requireable + browserifyable by removing the global envify transform

2.1.0 - 2015-06-15
* FIX : #29 Avoid callback for outdated queries
* FIX : #64 Sum up the processing time of all queries
* FIX : #92 Parameters that can be set in the dashboard shouldn't have
* FIX: #29 Avoid callback for outdated queries
* FIX: #64 Sum up the processing time of all queries
* FIX: #92 Parameters that can be set in the dashboard shouldn't have
defaults
* FIX : #62 Make sure disctinct is set to false when it's not possible to
* FIX: #62 Make sure disctinct is set to false when it's not possible to
use distinct in Algolia
* FEATURE : #91 Support for tags (with support for the raw format #98)
* FEATURE : #70 Ability to get all refined values : helper.getRefinements(
* FEATURE: #91 Support for tags (with support for the raw format #98)
* FEATURE: #70 Ability to get all refined values: helper.getRefinements(
facetname )
* FEATURE : #51 multiple filters for a single conjunctive facet (tests)
* FEATURE : Ability to modify any parameter of the state easily (#76 #84 #12)
* FEATURE : #69 Ability to know if a facet is refined, whatever the value
* FEATURE : #86 Expose SearchParameters, AlgoliaSearchHelper, SearchResults to
* FEATURE: #51 multiple filters for a single conjunctive facet (tests)
* FEATURE: Ability to modify any parameter of the state easily (#76 #84 #12)
* FEATURE: #69 Ability to know if a facet is refined, whatever the value
* FEATURE: #86 Expose SearchParameters, AlgoliaSearchHelper, SearchResults to
users directly in the builds
* FEATURE : #25 let the user do a clearRefinement with a function as a filter
* REFACTORING : SearchParameters is immutable (#14)
* REFACTORING : Ensure SearchParameters is totally frozen (#14)
* LIB : Update lodash version to 3.9.x
* FEATURE: #25 let the user do a clearRefinement with a function as a filter
* REFACTORING: SearchParameters is immutable (#14)
* REFACTORING: Ensure SearchParameters is totally frozen (#14)
* LIB: Update lodash version to 3.9.x

2.0.4
* FIX : #82 Fix facet count on records with multiple values for a single
* FIX: #82 Fix facet count on records with multiple values for a single
facet
* FEATURE: Add exhaustive attribute to a facet and removed useless timeout
(#80)

2.0.3 - 2015-05-13
* FIX : #72 add back the ability to do multiple disjunctive facetting on a
* FIX: #72 add back the ability to do multiple disjunctive facetting on a
single attribute
* FEATURE : #73 method to replace the state, without triggering a change
event : overrideStateWithoutTriggeringChangeEvent (use wisely)
* FEATURE : #66 add setTypoTolerance to SearchParameters
* FEATURE: #73 method to replace the state, without triggering a change
event: overrideStateWithoutTriggeringChangeEvent (use wisely)
* FEATURE: #66 add setTypoTolerance to SearchParameters

2.0.2 - 2015-05-06
* FIX : setHitsPerPage was creating a new property HitsPerPage instead of
* FIX: setHitsPerPage was creating a new property HitsPerPage instead of
updating the currently available hitsPerPage

2.0.1
* MEH : because of jsDelivr
* MEH: because of jsDelivr

2.0.0
* FIX : set page to 0 if it might change the number of pages returned
* FIX : handle distinct parameter automatically
* FIX : batch response handler gets the proper search state
* FEATURE : (breaking) Now peer depend on algoliasearch v3.1
* FEATURE : (breaking) Facets stats and timeout infos are consistently
* FIX: set page to 0 if it might change the number of pages returned
* FIX: handle distinct parameter automatically
* FIX: batch response handler gets the proper search state
* FEATURE: (breaking) Now peer depend on algoliasearch v3.1
* FEATURE: (breaking) Facets stats and timeout infos are consistently
grouped in the facet object in the SearchResults
* FEATURE : (breaking) no more extra queries
* FEATURE : (breaking) Facets results are stored in an array with an order
* FEATURE: (breaking) no more extra queries
* FEATURE: (breaking) Facets results are stored in an array with an order
that reflects their definition.
* FEATURE : Search results explicit definition
* FEATURE : (breaking) Search parameters as a separate object
* FEATURE : (breaking) Move callback style to a event based API
* FEATURE : change and results events return the state and the results (if any)
* FEATURE : SearchRefults.getFacetByName to retrieve a facet object from its
* FEATURE: Search results explicit definition
* FEATURE: (breaking) Search parameters as a separate object
* FEATURE: (breaking) Move callback style to a event based API
* FEATURE: change and results events return the state and the results (if any)
* FEATURE: SearchRefults.getFacetByName to retrieve a facet object from its
name
* FEATURE : SearchParameters.getNumericRefinement : get back the value of a specific numeric
* FEATURE: SearchParameters.getNumericRefinement: get back the value of a specific numeric
refinement
* FEATURE : clear refinements by name
* FEATURE : isDisjunctiveRefined to check if a disjunctive facet is refined
* FEATURE : basic support for numeric filters
* FEATURE : version number on the main helper factory
* TESTS : defaults test
* FEATURE: clear refinements by name
* FEATURE: isDisjunctiveRefined to check if a disjunctive facet is refined
* FEATURE: basic support for numeric filters
* FEATURE: version number on the main helper factory
* TESTS: defaults test

1.1.0
* REFACTORING : constructor, now expose the defaults
* TESTS : defaults test
* REFACTORING: constructor, now expose the defaults
* TESTS: defaults test
* FEATURE: Allow .search(q, params, cb) "callback always last" convention
introduced by JavaScript client, also on the helper

Expand Down
34 changes: 17 additions & 17 deletions README.md
Expand Up @@ -33,24 +33,24 @@ This is the library you will need to easily build a good search UX like our [ins
A small example that uses Browserify to manage modules.

```javascript
var algoliasearch = require( "algoliasearch" );
var algoliasearchHelper = require( "algoliasearch-helper" );
var algoliasearch = require('algoliasearch');
var algoliasearchHelper = require('algoliasearch-helper');

var client = algoliasearch( "app_id", "secret" );
var client = algoliasearch('app_id', 'secret');

var helper = algoliasearchHelper( client, "myMainIndex", {
facets : [ "mainCharacterFirstName", "year" ],
disjunctiveFacets : [ "director" ]
var helper = algoliasearchHelper(client, 'myMainIndex', {
facets: ['mainCharacterFirstName', 'year'],
disjunctiveFacets: ['director']
});

helper.on( "result", function( data ){
console.log( data.hits );
} );
helper.on('result', function(data){
console.log(data.hits);
});

helper.addDisjunctiveRefine( "director", "Clint Eastword" );
helper.addDisjunctiveRefine( "director", "Sofia Coppola" );
helper.addDisjunctiveRefine('director', 'Clint Eastword');
helper.addDisjunctiveRefine('director', 'Sofia Coppola');

helper.addNumericRefinement( "year", "=", 2003 );
helper.addNumericRefinement('year', '=', 2003);

// Search for any movie filmed in 2003 and directed by either C. Eastwood or S. Coppola
helper.search();
Expand All @@ -62,19 +62,19 @@ helper.search();

[See the examples in action](http://algolia.github.io/algoliasearch-helper-js/)

### Use with NPM
### With NPM

`npm install algoliasearch-helper`

### Use with bower
### With bower

`bower install algoliasearch-helper`

### Use the CDN
### Regular `<script>` tag

Include this in your page :
Use our [jsDelivr](http://www.jsdelivr.com/) build:

`<script src="//cdn.jsdelivr.net/algoliasearch.helper/2.0.0/algoliasearch.helper.min.js"></script>`
`<script src="//cdn.jsdelivr.net/algoliasearch.helper/2/algoliasearch.helper.min.js"></script>`

## How to contribute?

Expand Down
16 changes: 8 additions & 8 deletions examples/instantsearch+helper+angular.html
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width,initial-scale=1">
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-sanitize.min.js"></script>
Expand All @@ -21,21 +22,21 @@
<div class="facets-wrapper">
<h1>Disjunctive Facets</h1>
<div ng-repeat="facet in content.disjunctiveFacets">
<h4>{{ facet.name }}</h4>
<h4>{{facet.name}}</h4>
<div class="checkbox" ng-repeat="(value, count) in facet.data">
<label>
<input type="checkbox" ng-checked="helper.isDisjunctiveRefined(facet.name, value)" ng-click="toggleRefine($event, facet.name, value)" />
{{ value }} ({{ count }})
{{value}} ({{count}})
</label>
</div>
</div>
</div>
<div class="facets-wrapper">
<h1>Facets</h1>
<div ng-repeat="facet in content.facets">
<h4>{{ facet.name }}</h4>
<h4>{{facet.name}}</h4>
<li ng-class="{ refined: helper.isRefined(facet.name, value) }" ng-repeat="(value, count) in facet.data">
<a href="#" ng-click="toggleRefine($event, facet.name, value)">{{ value }}</a> ({{ count }})
<a href="#" ng-click="toggleRefine($event, facet.name, value)">{{value}}</a> ({{count}})
</li>
</div>
</div>
Expand All @@ -45,7 +46,7 @@ <h4>{{ facet.name }}</h4>
<h1>Results</h1>
<div class="hit panel" ng-repeat="hit in content.hits">
<div class="attribute" ng-repeat="(attribute, highlight) in hit._highlightResult">
<strong>{{ attribute }}:</strong>
<strong>{{attribute}}:</strong>
<span ng-bind-html="highlight.value"></span>
</div>
</div>
Expand All @@ -64,7 +65,7 @@ <h1>Results</h1>
disjunctiveFacets: ['category', 'manufacturer'],
hitsPerPage: 5,
maxValuesPerFacet: 5,
getRankingInfo : true
getRankingInfo: true
});

$scope.helper.on('result', function(content) {
Expand All @@ -85,6 +86,5 @@ <h1>Results</h1>
$scope.helper.search();
}]);
</script>

</body>
</html>
24 changes: 12 additions & 12 deletions examples/instantsearch+helper+excludes.html
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width,initial-scale=1">
<script src="//code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="//cdn.jsdelivr.net/algoliasearch/3/algoliasearch.min.js"></script>
Expand Down Expand Up @@ -52,27 +53,26 @@ <h1>Results</h1>
maxValuesPerFacet: 5
});

helper.on( "result", searchCallback );
$inputfield.keyup( search );
helper.on("result", searchCallback);
$inputfield.keyup(search);

window.toggleRefine = function(facet, value) {
helper.toggleRefine(facet, value).search();
}
};

window.toggleExclude = function(facet, value) {
helper.toggleExclude(facet, value).search();
}
};

search();

//Functions

function search() {
helper.setQuery( $inputfield.val() ).search();
helper.setQuery($inputfield.val()).search();
}

function searchCallback( content ) {
console.log( content );
function searchCallback(content) {
if (content.query != $inputfield.val()) {
// do not consider out-dated queries
return;
Expand Down Expand Up @@ -103,8 +103,8 @@ <h1>Results</h1>

// Scan all disjunctive facets and display them
var facets = '';
for ( var i = 0; i < content.disjunctiveFacets.length; i++ ){
var facet = content.disjunctiveFacets[ i ];
for (var i = 0; i < content.disjunctiveFacets.length; i++){
var facet = content.disjunctiveFacets[i];
facets += '<h4>' + facet.name + '</h4>';
var values = facet.data;
for (var value in values) {
Expand All @@ -118,8 +118,8 @@ <h1>Results</h1>

// Scan all facets and display them
facets = '';
for( var i = 0; i < content.facets.length; i++ ){
var facet = content.facets[ i ];
for(var i = 0; i < content.facets.length; i++){
var facet = content.facets[i];
facets += '<h4>' + facet.name + '</h4>';
facets += '<ul>';
var values = facet.data;
Expand Down

0 comments on commit 6aefd52

Please sign in to comment.